note 105923 deleted from function.json-encode by cmb

From: Date: Sun, 04 Nov 2018 10:01:24 +0000
Subject: note 105923 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209603@lists.php.net to get a copy of this message
Note Submitter: rob at weeverapps dot com ---- If, for some reason you need to force a single object to be an array, you can use array_values() -- this can be necessary if you have an array with only one entry, as json_encode will assign it as an object otherwise : <?php $object[0] = array("foo" => "bar", 12 => true); $encoded_object = json_encode($object); ?> output: {"1": {"foo": "bar", "12": "true"}} <?php $encoded = json_encode(array_values($object)); ?> output: [{"foo": "bar", "12": "true"}]

« previous php.notes (#209603) next »