0

这是数组,如何获取 id "573" 的 Key

Array (
    [0] => Array ( 
        [0] => stdClass Object ( [id] => 577 [name] => BPO Manager  ) 
        [1] => stdClass Object ( [id] => 578 [name] => BPO User  ) 
        [2] => stdClass Object ( [id] => 575 [name] => user2 ) 
        [3] => stdClass Object ( [id] => 573 [name] => Site Admin  ) 
    ) 
);
4

3 回答 3

0

尝试这个

foreach ($arr as $key => $arr1) {
       foreach ($arr1 as $key1 => $obj) {
           if ($obj->id == '573') {
             return $obj->name;
           }
       }
    }
于 2013-09-16T08:18:26.350 回答
0

你可以像这样得到它:

$array[0][3]->id;
于 2013-09-16T08:08:30.037 回答
0
$key=573;
var_dump(search($arr,573));

function search($yourArray,$key)
{
    foreach($yourArray[0] as $object)
    {
     if ($object->key==$key)
        {
          return $object->id;
        }
    }
    return false;
}
于 2013-09-16T08:08:47.087 回答