dqyitt2954 2014-10-16 04: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 04: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部