After json_encode is converted into an array, why cannot the value be obtained based on the key name? Ask a white question .. PHPcode $ arr = array (34 = & gt; 1, 2 = & gt; 3); $ str = json_encode ($ arr); echo $ str; $ arr2 = (array) json_decode ($ str); why can't the value be obtained based on the key name after the echo json_encode is converted into an array?
Ask a white question ..
PHP code
$ Arr = array (34 => 1, 2 => 3); $ str = json_encode ($ arr); echo $ str; $ arr2 = (array) json_decode ($ str ); echo''; Print_r ($ arr2); echo'
'; Var_dump ($ arr2 ['2']);
Why can't I retrieve the value based on the key value after the JSON encode converted from the index array is obtained?
How can I obtain the value of $ arr2 ['2?
------ Solution --------------------
$ Arr2 = json_decode ($ str, 1 );
------ Solution --------------------
By default, it is converted to an object.
------ Solution --------------------
If you want to forcibly generate a PHP join array, json_decode () requires a parameter true: