通过stdClass迭代

时间:2013-01-07 16:40:25

标签: php arrays

如何从地球上获取id和此数组中的名称(可能使用ForEach结构)?

stdClass Object (
 [data] => Array ( 
    [0] => stdClass Object ( [name] => Corinne Culbard [id] => 5005561918 ) 
    [1] => stdClass Object ( [name] => Tom West [id] => 5034297044 ) 
    [2] => stdClass Object ( [name] => Sabri Tasci [id] => 5057373639 )

1 个答案:

答案 0 :(得分:3)

这不起作用吗?

foreach ($object->data as $item) {
    $name = $item->name;
    $id = $item->id;
}