我试图从定义如下的数据中取出文件:
$ ARR [$ d] [$ player_number] [' FIELD_NAME'];
我在数组中有两个字段:名称和评级。我打印数组时的输出是:
Array ( [$j] => Array ( [names] => "some name" [rating] => "some number" ))
我的问题是,我无法取得字段"名称"和"评级"当我为每个"做"时,在同一个循环中。当我单独进行时 - 它可以正常工作,但我无法正常对表进行排序。 我知道我必须使用"列表"在某种程度上,我试图执行它,但没有成功。
我正在做的是:
function get_array_column($array, $column)
{
$ret = array();
foreach ($array as $row) $ret[] = $row[$column];
return $ret;
}
for($i=1;$i<=$num_groups;$i++)
{
$a = array();
$a = get_array_column($arr[$i],'names');
foreach ($a as $value)
{
echo $value;
}
}
感谢。
答案 0 :(得分:1)
将数组定义为
[0] => Array ( [name] => name0
[fieldname] => fieldname0 ) [1] => Array ( [name] => name1 [fieldname] => fieldname1 )
foreach ($arr as $key){
echo $key['names'];
echo $key['ratings'];
}
答案 1 :(得分:0)
你有一个三维数组。
也许你想要这样的东西:
一个数组,由玩家的号码表示
$array[$player_number]
在此数组中,您可以添加stdClass对象,其中包含播放器的名称和评级。代码看起来像这样
//create players array
$players = array();
//create a player
$player = new stdClass();
$player->number = 342;
$player->name = "Matt Click";
$player->rating = 13;
// add a player to the players array
$players[$player->number] = $player;
... // some code
// foreach through the players
foreach ($players as $player)
{
echo "Name: ".$player->name." rating:".$player->rating."\n";
}