|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-10-29 16:55 UTC] rasmus@php.net
-Status: Open
+Status: Wont fix
[2010-10-29 16:55 UTC] rasmus@php.net
[2010-10-30 11:06 UTC] pratik dot vanol at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 09:00:02 2025 UTC |
Description: ------------ Hi, I am having one issues with json_encode function. Let me explain briefly. I want the json represented string from PHP Array. When I pass the array with not actually given 'key' value. json_encode return the encoded string as array. But after giving the array with associative array it is forcefully generated encoded as an object. In short : I can forcefully get the output of json_encode as an Object (using JSON_FORCE_OBJECT as 2nd Argument)) But can not forcefully get the output of json_encode as an Array (!!!?) I really need josn_encode as an array in my functionality no matter key is given or not. Like added the JSON_FORCE_OBJECT there must be something for array. ignore keys should be pass in optional argument. Please do not say this is actual behavior of json. I need this solution in anyhow. Test script: --------------- <?php /*I am giving array with no keys or numeric start with 0,2,3,4....with break sequence*/ $array = array("0" => "value1", "1" => "value2", "2" => "value3", "3" => "value4"); echo "Array output as array: ", json_encode($array); echo "<br />"; /*I am giving array with no keys or numeric start with 0,2,3,4....with break sequence*/ $array = array("0" => "value1", "3" => "value2", "3" => "value3", "6" => "value4"); echo "Array output should be array: ", json_encode($array); // Need output as an Array here shows as an Object forcefully Expected result: ---------------- //Expected result: Array output as array : ["value1","value2","value3","value4"] Array output should be array: ["value1","value2","value3","value4"] Actual result: -------------- //Actual result: Array output as array: ["value1","value2","value3","value4"] Array output should be array: {"0":"value1","3":"value3","6":"value4"}