PHP - 处理数组

时间:2011-07-06 01:38:49

标签: php arrays

假设我有一个如下数组,我如何“检查vid = 2,然后获取/ echo tid”?

Array
(
    [29] => stdClass Object
        (
            [tid] => 29
            [vid] => 2
            [name] => notebook
            [description] => 
            [weight] => 0
            [language] => 
            [trid] => 0
        )

    [97] => stdClass Object
        (
            [tid] => 97
            [vid] => 1
            [name] => DELL
            [description] => 
            [weight] => 0
            [language] => 
            [trid] => 0
        )

)

2 个答案:

答案 0 :(得分:5)

foreach($vids as $vid){
    if($vid->vid == 2){
        echo $vid->tid;
    }
}

答案 1 :(得分:0)

它应该是:

  foreach($tid as $key => $value){
    if($value->vid == 2){
        echo $value->tid;
    }
  }