试图通过foreach中的第3个foreach获得json字段值

时间:2014-06-06 00:41:37

标签: php

我正在尝试获取订阅者ID的值但我在第3个foreach上获得了php错误。

$content = '{"12345":{"id":"123","data":{"sort":"desc","subcriber":{"id":321"}}}';
$json = json_decode($content, true);

foreach($json as $row => $val) {
    echo $val['id'];
    $jdata = $val['data'];

    foreach($jdata as $data => $val2) {
        echo $val2['sort'];
        $jsubcriber = $val2['subcriber'];

        foreach($jsubcriber as $subcriber => $val3) {
            echo $val3['id'];

        }
    }
}

1 个答案:

答案 0 :(得分:0)

应该是:

echo $jsubscriber['id'];

$jsubscriber是一个关联数组,而不是关联数组的数组。