Echo a multi dimensional array(回显多维数组)
问题描述
我有一个《使命召唤 4》玩家列表的多维数组.当我尝试回显该数组时,它返回 Array
30 次,因为服务器中有 30 个当前玩家.
I have an multidimensional array of a player list for Call of Duty 4. When I try to echo the array it comes back with Array
30 times because there are 30 current players in the server.
$promodplist 的 Var_Dump(玩家列表)
Var_Dump of $promodplist (Players List)
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)
这就是我试图用来列出当前球员的内容.
And this is what I am trying to use to list the current players.
$promodplist = $data['promod']['players'];
foreach($promodplist as $k => $v)
我只是想回显每个数组中的 nick
(昵称).
I just simply want to echo out the nick
(nickname) in each array.
推荐答案
$promodplist = $data['promod']['players'];
foreach($promodplist as $k => $v)
print($v['nick']);
应该做你想做的.foreach
遍历数组中的键/值对,其中 $k
是元素的键(在您的情况下是基于 0 的索引),而 $v
是值(玩家数据的数组,对于您而言).您可以通过使用其名称作为 数组访问器.
Should do what you want. foreach
iterates through the key/value pairs in the array, where $k
is the element's key (a 0-based index, in your case) and $v
is the value (an array of player data, for you). You can access the rest of the information by using its name as the key in the array accessor.
这篇关于回显多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:回显多维数组
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- HTTP 与 FTP 上传 2021-01-01