我正在尝试从多维数组中返回一个值,但它似乎没有工作。
数组 -
[players] => Array
(
[0] => Array
(
[player] => Necro
[score] => 0
[deaths] => 0
[gq_name] =>
[gq_kills] =>
[gq_deaths] => 0
[gq_score] => 0
[gq_ping] =>
)
)
PHP Foreach
<?php
$dayzplayers = $results["dayz"]["players"];
foreach($dayzplayers as $k => $v) {
echo ' <b>'.$v["player"].'</b>';
} ?>
答案 0 :(得分:1)
['player']索引似乎在SOH(标题开头)键中有一个不可见的控制字符
尝试使用echo ' <b>'.$v[chr(1) . "player"].'</b>';
代替echo ' <b>'.$v["player"].'</b>';
答案 1 :(得分:0)
如果数据是您在第一个列表中发布的数据,则应该可以使用:
foreach($dayzplayers as $player) {
echo $player[chr(1).'player'];
}