Parse JSON string contents into PHP Array

前端 未结 4 1779
孤街浪徒
孤街浪徒 2020-11-29 10:31

I am trying to parse a string in JSON, but not sure how to go about this. This is an example of the string I am trying to parse into a PHP array.

$json = \'{         


        
4条回答
  •  春和景丽
    2020-11-29 11:13

    It can be done with json_decode(), be sure to set the second argument to true because you want an array rather than an object.

    $array = json_decode($json, true); // decode json
    

    Outputs:

    Array
    (
        [id] => 1
        [name] => foo
        [email] => foo@test.com
    )
    

提交回复
热议问题