PHP- Decode JSON

前端 未结 3 1324
陌清茗
陌清茗 2020-11-30 16:13

I have the following script to get search results from an API and then slice the array and dump it, I am having trouble decoding the JSON into an array, it returns Arr

3条回答
  •  臣服心动
    2020-11-30 16:18

    Separate your php from html please, use indentation and:

    $array = json_decode($data, TRUE); //second param used for associative array return
    
    Example #1 json_decode() examples
    
    The above example will output:
    object(stdClass)#1 (5) {
        ["a"] => int(1)
        ["b"] => int(2)
        ["c"] => int(3)
        ["d"] => int(4)
        ["e"] => int(5)
    }
    
    array(5) {
        ["a"] => int(1)
        ["b"] => int(2)
        ["c"] => int(3)
        ["d"] => int(4)
        ["e"] => int(5)
    }
    

    P.S: From the Bible (http://php.net/manual/en/function.json-decode.php)

提交回复
热议问题