我有一個for循環,輸出json_decode()中的兩個數組;我想知道如何獲得第一個數組的數據,或者第二個數組的數據。for循環中的多個數組需要使用json輸出
for($i = 0; $i < $node_count; $i++)
{
$results[$i] = curl_multi_getcontent ($curl_arr[$i] );
$results[$i] = json_decode($results[$i],true);
}
我得到$ results [0]和$ results [1]。
我只能輸出的$結果[0]
echo "<pre>";
print_r($results[0]);
echo "</pre>";
這使我沒有錯誤,我只能輸出第一陣列。然而,當我嘗試這
foreach($results[0] as $result){
$result['data']['id'];
}
它給我一個未定義的索引的錯誤。但是,如果我試圖不[0]
foreach($results as $result){
$result['data']['id'];
}
此輸出兩個陣列中的ID,但我只是想獲得一個陣列。這是爲什麼發生?
謝謝!
編輯:
array(
array(
'data' => array('id' => ...),
....
),
...
)
array(
array(
'data' => array('id' => ...),
....
),
...
)
我怎麼能print_r($ results [0])?我會在什麼地方使用? – hellomello
@andrewliu他們都是數組,請參閱我的編輯。 – xdazz
感謝您的迴應,但是如果我有結果[0]和結果[1]輸出並且我只想從第一個數組中獲取值,該怎麼辦?我編輯了我的帖子,顯示了兩個數組 – hellomello