note 107616 modified in function.json-encode by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:36:31 +0000 |
| Subject: | note 107616 modified in function.json-encode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187817@lists.php.net to get a copy of this message | ||
WARNING! Do not pass associative arrays if the order is important to you. It seems that while
FireFox does keep the same order, both Chrome and IE sort it. Here's a little
workaround: <?php 		$arWrapper
= array();		 		$arWrapper['k'] =
array_keys($arChoices); 		$arWrapper['v'] =
array_values($arChoices); 		$json =
json_encode($arWrapper); ?>
--was--
WARNING! Do not pass associative arrays if the order is important to you. It seems that while
FireFox does keep the same order, both Chrome and IE sort it. Here's a little workaround:
$arWrapper = array();
$arWrapper['k'] = array_keys($arChoices);
$arWrapper['v'] = array_values($arChoices);
$json = json_encode($arWrapper);
http://php.net/manual/en/function.json-encode.php