Getting an array result from json_decode

前端 未结 5 1061
逝去的感伤
逝去的感伤 2020-12-20 17:24

How do I get an array as a result from json_decode()?

I had an array like this:

$array = array(
  \'mod_status\' => \'yes\',
  \'mod_         


        
5条回答
  •  清酒与你
    2020-12-20 17:55

    If you only use that data in PHP I recommend using serialize and unserialize instead or else you'll never be able to differentiate between objects and associative arrays, because the object class information is lost when encoding to JSON.

    1, 'b'=>2);
    $y = new myClass;
    $y->a = 1;
    $y->b = 2;
    echo json_encode($x), "\n", json_encode($y); // identical
    echo "\n", serialize($x), "\n", serialize($y); // not identical
    ?>
    

    Run it.

提交回复
热议问题