Parsing JSON array with PHP foreach

后端 未结 3 756
广开言路
广开言路 2020-11-29 04:09

Wondering why my PHP code will not display all \"Value\" of \"Values\" in the JSON data:

$user = json_decode(file_get_contents($analytics));
foreach($user-&g         


        
3条回答
  •  猫巷女王i
    2020-11-29 04:46

    $user->data is an array of objects. Each element in the array has a name and value property (as well as others).

    Try putting the 2nd foreach inside the 1st.

    foreach($user->data as $mydata)
    {
        echo $mydata->name . "\n";
        foreach($mydata->values as $values)
        {
            echo $values->value . "\n";
        }
    }
    

提交回复
热议问题