索引处的键值

时间:2012-03-08 22:01:17

标签: php arrays

我的php中有这个数组:

 Array ( 
    [0] => Array ( 
        [catId] => 0
        [catName] =>0
        [hasSubCategory] => 0 
        [hasSubView] => 0 
    ) 
    [1] => Array ( 
        [catId] => 1020 
        [catName] => apple 
        [hasSubCategory] => 0 
        [hasSubView] => 1 
    )
    [2] => Array ( 
        [catId] => 1040 
        [catName] => orange
        [hasSubCategory] => 1 
        [hasSubView] => 0 
    )

如何打印catId.value = 1040的catName.value?

在这种情况下,输出应为“橙色”;

2 个答案:

答案 0 :(得分:4)

试试这个

foreach($arr as $v)
{
  if($v['catId']==1040)
  {
    echo $v['catName'];
    break;
  }
}

我希望它会有所帮助。

答案 1 :(得分:0)

if ($array['0']['catId'] == 1040): print_r($array['0']['catName']) endif;