note 130664 added to function.json-decode

From: Date: Fri, 20 Feb 2026 23:41:14 +0000
Subject: note 130664 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-222556@lists.php.net to get a copy of this message
If you json_encode() an associative array it is encoded as an object, not an array. For example echo json_encode( ["a"=>42, "b"=>99] ); will result in: {"a":42,"b":99} which is the JSON representation of an object, not an array. The encode has lost the information that this was an array originally. So this means if you decode the above it will refuse to accept it as an argument for any array functions. You can cast it to an array or set the second parameter in the decode, but that assumes you were the one that encoded it and knew it was supposed to be an array. ---- Server IP: 206.189.2.9 Probable Submitter: 67.174.192.177 ---- Manual Page -- https://php.net/manual/en/function.json-decode.php Edit -- https://main.php.net/note/edit/130664 Del: integrated -- https://main.php.net/note/delete/130664/integrated Del: useless -- https://main.php.net/note/delete/130664/useless Del: bad code -- https://main.php.net/note/delete/130664/bad+code Del: spam -- https://main.php.net/note/delete/130664/spam Del: non-english -- https://main.php.net/note/delete/130664/non-english Del: in docs -- https://main.php.net/note/delete/130664/in+docs Del: other reasons-- https://main.php.net/note/delete/130664 Reject -- https://main.php.net/note/reject/130664 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222556) next »