note 105923 added to function.json-encode

From: Date: Mon, 26 Sep 2011 04:15:27 +0000
Subject: note 105923 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-183425@lists.php.net to get a copy of this message
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 : $object[0] = array("foo" => "bar", 12 => true); $encoded_object = json_encode($object); output: {"1": {"foo": "bar", "12": "true"}} $encoded = json_encode(array_values($object)); output: [{"foo": "bar", "12": "true"}] ---- Server IP: 69.147.83.197 Probable Submitter: 24.141.19.142 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/105923 Del: integrated -- https://master.php.net/note/delete/105923/integrated Del: useless -- https://master.php.net/note/delete/105923/useless Del: bad code -- https://master.php.net/note/delete/105923/bad+code Del: spam -- https://master.php.net/note/delete/105923/spam Del: non-english -- https://master.php.net/note/delete/105923/non-english Del: in docs -- https://master.php.net/note/delete/105923/in+docs Del: other reasons-- https://master.php.net/note/delete/105923 Reject -- https://master.php.net/note/reject/105923 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183425) next »