dtgvl48608 2014-03-22 16:45
浏览 301
已采纳

如何从数组中获取特定数据?

Right now I have a problem with retrieving data form arrays, maybe it's really simple (probably it is) but I am struggling wiht it since morning and it appears, that my knowledge about PHP is worth nothing...so I have few arrays:

array( "name" => "Array 1",
    "type" => "array"),

array( "name" => "Array 2",
    "type" => "whatever"),

array( "name" => "Array 3",
    "type" => "whatever"),

array( "name" => "Array 4",
    "type" => "array"),

array( "name" => "Array 5",
    "type" => "whatever"),

What I need to do is to display 'name' of arrays of the 'array' type, I know I need a foreach loop but how to construct 'foreach ($arrays as $array) {' to get the desired result?

EDIT

Thanks for all the replies, but I tihnk I didn't make myself clear. I need to display "name" only when there is a "type" => "array" present within array, every other arrays' "name" should be omitted.

  • 写回答

3条回答 默认 最新

  • doukanxi4246 2014-03-22 16:47
    关注

    You'll need to do something like this:

    foreach($arrays as $array) {
        if($array['type'] == 'array') {
            print($array['name']);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条