PHP Object conversion question

Posted by karlthorwald on Stack Overflow See other posts from Stack Overflow or by karlthorwald
Published on 2010-05-17T23:25:39Z Indexed on 2010/05/17 23:30 UTC
Read the original article Hit count: 280

Filed under:
|
|

I am converting from JSON to object and from object to array. It does not what I expected, can you explain to me?

$json = '{"0" : "a"}';
$obj = json_decode($json);
$a = (array) $obj;
print_r($a);
echo("a0:".$a["0"]."<br>");

$b = array("0" => "b");
print_r($b);
echo("b0:".$b["0"]."<br>");

The output here is:

Array ( [0] => a ) a0:
Array ( [0] => b ) b0:b

I would have expected a0:a at the end of the first line.

© Stack Overflow or respective owner

Related posts about php

Related posts about json-decode