这是数组,如何获取id为“573”的密钥
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 )
)
);
答案 0 :(得分:0)
你可以这样:
$array[0][3]->id;
答案 1 :(得分: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;
}
答案 2 :(得分:0)
试试这个
foreach ($arr as $key => $arr1) {
foreach ($arr1 as $key1 => $obj) {
if ($obj->id == '573') {
return $obj->name;
}
}
}