|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2010-05-26 08:30 UTC] laruence at yahoo dot com dot cn
 Description:
------------
php treat numeric string key as interge,
bug sometimes there is some exception.
for example:
  while change a std object to array, numeric string key doesn't cast to number 
Test script:
---------------
<?php
$data = array(
    123 => 'laruence',
    "03"=> 'baidu',
);
$value = json_encode($data);
$obj   = json_decode($value);
$arr   = (array)$obj;
var_dump($arr);
?>
Expected result:
----------------
array(2) {
  [123]=>
  string(8) "laruence"
  ["03"]=>
  string(5) "baidu"
}
Actual result:
--------------
array(2) {
  ["123"]=>
  string(8) "laruence"
  ["03"]=>
  string(5) "baidu"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 05:00:02 2025 UTC | 
there is an easier way to build such an array. $obj = new stdClass; $obj->{'123'} = 1; $arr = (array) $obj; var_dump($obj);