我有一個數組,我想從中獲取某些信息並使用php/html(即遊戲,編號,評級)輸出它。儘管我只從輸出中的第一個數組中獲取信息,但我已經完成了基礎知識。我知道循環是我需要做的,儘管我不確定如何一次返回多個記錄。一個數組中的某些信息可能不在另一個數組中,因爲您可以看到第一個數組中沒有[info]。循環通過多維數組和打印
這裏是我的代碼:
<?php
$review = $developer->api('/source');
function d($d){
echo '<pre>';
print_r($d);
echo '</pre>';
}
d($review[data][0][game]);
d($review[data][0][game][rating]);
?>
這是輸出:
Array([data] => Array ([0] => Array ([id] => 2010_1110 [from] => Array ([name] => Pebkac [id] => 11001010 ) [game] => Array ([id] => 2112 [name] => New Game [rating] => Array ([action] => 9 [graphics] => 10)) [comments] => Array ([data] => Array ([0] => Array ([id] => 2010_1111 [from] => Array ([name] => My Friend [id] => 10100110) [message] => hi there. [created_time] => 8:00 P.M.)))))
[paging] => Array ([previous] => url1 [next] => url2))
Array([data] => Array ([1] => Array ([id] => 2010_1112 [from] => Array ([name] => Pebkac [id] => 11001010 ) [game] => Array ([id] => 5050 [name] => Another Game [rating] => Array ([action] => 8 [graphics] => 8)) [info] => [created_time] => 8:59 P.M. [owns] => Array ([data] => Array ([0] => Array ([id] => 20100112 [name] => Friend Two))) [comments] => Array ([data] => Array ([0] => Array ([id] => 2010_1113 [from] => Array ([name] => My Friend [id] => 10100110) [message] => hi there. [created_time] => 9:00 P.M.)))))
http://stackoverflow.com/questions/16141590/printing-a-multi-dimensional-array-in-table-using-for-loop – 2016-04-13 07:31:54