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

在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.

  • 写回答

2条回答 默认 最新

  • dongshanjin8947 2014-10-16 12:25
    关注

    once you defined your array as

    [0] => Array ( [name] => name0 
    [fieldname] => fieldname0 ) [1] => Array ( [name] => name1 [fieldname] => fieldname1 )
    
    foreach ($arr as $key){
    
    echo $key['names'];
    
    echo $key['ratings'];
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探