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 WPF动态创建页面内容
  • ¥15 如何对TBSS的结果进行统计学的分析已完成置换检验,如何在最终的TBSS输出结果提取除具体值及如何做进一步相关性分析
  • ¥15 SQL数据库操作问题
  • ¥100 关于lm339比较电路出现的问题
  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线