我有一個多維數組,用於使命召喚4的播放列表。當我嘗試回顯陣列時,它會以Array
來回30次,因爲服務器中有30個當前播放器。回聲多維數組
$ promodplist的的var_dump(玩家列表)
array(27) {
[0]=> array(6) {
["frags"]=> string(1) "0"
["ping"]=> string(2) "26"
["nick"]=> string(10) "DIVINEBRAH"
["gq_name"]=> string(10) "DIVINEBRAH"
["gq_score"]=> string(1) "0"
["gq_ping"]=> string(2) "26"
}
[1]=> array(6) {
["frags"]=> string(1) "0"
["ping"]=> string(2) "35"
["nick"]=> string(7) "><> <><"
["gq_name"]=> string(7) "><> <><"
["gq_score"]=> string(1) "0"
["gq_ping"]=> string(2) "35"
}
[2]=> array(6) {
["frags"]=> string(1) "0"
["ping"]=> string(2) "42"
["nick"]=> string(10) "xXthe0neXx"
["gq_name"]=> string(10) "xXthe0neXx"
["gq_score"]=> string(1) "0"
["gq_ping"]=> string(2) "42"
}
$servers['promod'] = array('cod4', '67.202.102.224');
$servers['promod2'] = array('cod4', '67.202.102.224');
$gq = new GameQ();
$gq->addServers($servers);
$results = $gq->requestData();
function print_results($results) {
foreach ($results as $id => $data)
而這正是我試圖用它來列出當前的球員。
$promodplist = $data['promod']['players'];
foreach($promodplist as $k => $v)
我只是單純的想回聲出每個陣列中的nick
(暱稱)。
bkconrad的解決方案是正確的,以做你想做的事。要在PHP中打印出任何數組(包括多維數組)的內容,請使用[print_r()] [print]函數。 [print]:http://php.net/manual/en/function.print-r.php – 2012-08-06 03:51:15