|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-06-05 18:23 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 06:00:01 2025 UTC |
Description: ------------ After manipulating arrays using [] or creating an array in the form array("key" => value, ...) or calling unset on an array element. json_encode will encode the array as an object rather than an array. Reproduce code: --------------- echo json_encode(array(1 => new stdClass(), 2 => new stdClass(), 3 => new stdClass())); $m = array(); $m[1] = new stdClass(); $m[2] = new stdClass(); $m[3] = new stdClass(); echo json_encode($m); $m = array_values($m); echo json_encode($m); unset($m[0]); echo json_encode((array) $m); Expected result: ---------------- ["1":{},"2":{},"3":{}] ["1":{},"2":{},"3":{}] [{},{},{}] ["1":{},"2":{}] Actual result: -------------- {"1":{},"2":{},"3":{}} {"1":{},"2":{},"3":{}} [{},{},{}] {"1":{},"2":{}}