2017-04-20 91 views
-1

我有它輸出數組:PHP的foreach數組問題

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 

您的幫助將非常感謝! 魯珀特

+2

它不是一個數組是一個對象,所以你需要使用像obj- $>的firstName –

+0

使用'$ user_data-> firstName' –

回答

1

假設$ USER_DATA是對象的數組

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

這不起作用......但是這樣做:echo $ user_data-> firstName; – rupertbj