dqyitt2954
2014-10-16 12:03
浏览 143
已采纳

在php中从多个数组中取出字段

I'm trying to take out files out of an Array that defined like this:

$arr[$j][$player_number]['field_name'];

I have 2 fields in the array : names and rating. The output when I'm printing the array is :

Array ( [$j] => Array ( [names] => "some name" [rating] => "some number" ))

My problem is that I can't take the fields "names" and "rating" at the same loop when I'm doing "for each". When I'm doing it separately - it works but I can't sort it in a table normally. I know that I have to use the "list" in some way, I tried to execute it, but without success.

What I'm doing is :

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;
           }
    }

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试从这样定义的数组中取出文件:</ p> \ n

$ arr [$ j] [$ player_number] ['field_name']; </ p> </ blockquote>

我在数组中有2个字段: 名称和评级。 我打印数组时的输出是:</ p>

 数组([$ j] =&gt;数组([名称] =&gt;“某些名称”[rating] =  &gt;“某个数字”))
 </ code> </ pre> 
 
 

我的问题是我不能在同一个循环中取字段“名称”和“评级” 我做“为每个人”。 当我单独做它 - 它可以工作,但我不能正常在表中排序。 我知道我必须以某种方式使用“列表”,我试图执行它,但没有成功。</ p>

我正在做的是:</ p>

</ p> </ blockquote>

 <  code> function get_array_column($ array,$ column)
 {
 $ ret = array(); 
 foreach($ array as $ row)$ ret [] = $ row [$ column]; 
 return $ ret  ; 
} 
 for($ i = 1; $ i&lt; = $ num_groups; $ i ++)
 {
 $ a = array(); 
 $ a = get_array_column($ arr [$ i],'  names'); 
 foreach($ a as $ value)
 {
 echo $ value; 
} 
} 
 </ code> </ pre> 
 
 

谢谢。</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题