php foreach数组问题

时间:2017-04-20 10:37:51

标签: php arrays foreach linkedin

我有一个输出的数组:

stdClass Object ( [firstName] => Rupert [headline] => Managing Director at 
READ Advisors [lastName] => Bowen-Jones [pictureUrl] => 
https://media.licdn.com/mpr/mprx/0_yrLwHnXDTWGSypSo-
B_NHz9hiu52pMpoOAAqHzLxpolpijIEr9zbQvllDTL1xYj6g1FvFtBsywhL ) 

我试图挑选出每个项目:

foreach ($user_data as $key => $value) {
echo "<br />" . $value['firstName'] . "<br />";
}

但我收到以下错误:

stdClass Object ( [firstName] => Rupert [headline] => Managing Director at 
READ Advisors [lastName] => Bowen-Jones [pictureUrl] => 
https://media.licdn.com/mpr/mprx/0_yrLwHnXDTWGSypSo-
B_NHz9hiu52pMpoOAAqHzLxpolpijIEr9zbQvllDTL1xYj6g1FvFtBsywhL ) 
Warning: Illegal string offset 'firstName' in 
/home/readadvisors/readadvisors.com/auth/linkedin/callback.php on line 26

R

Warning: Illegal string offset 'firstName' in
/home/readadvisors/readadvisors.com/auth/linkedin/callback.php on line 26
M

Warning: Illegal string offset 'firstName' in 
/home/readadvisors/readadvisors.com/auth/linkedin/callback.php on line 26

B

Warning: Illegal string offset 'firstName' in
/home/readadvisors/readadvisors.com/auth/linkedin/callback.php on line 26
h

非常感谢您的帮助!! 鲁珀特

1 个答案:

答案 0 :(得分:1)

假设$ user_data是一个对象数组

foreach ($user_data as $key => $value) {
echo "<br />" . $value->firstName . "<br />";
}