我对这个问题感到相当愚蠢,但这是怎么回事?
foreach ($fbuser['feed']['data'] as $fbmsg){
var_dump($fbmsg['message']);
die;
产生我想要的确切结果,它显示数组键'message'的内容......
...虽然这会引发错误,指出键'message'未定义...
foreach ($fbuser['feed']['data'] as $fbmsg){
$r .= '<tr><td class="fb_td"><img src="https://graph.facebook.com/'.$fbmsg['from']['id'].'/picture" class="fb_img"></td><td>'.
' <i>'.$fbmsg['from']['name'].'</i><br>'.
$fbmsg['message'].'</td></tr>';
}
这是var_dump,显然包含['message']键......
array(19) { ["id"]=> string(28) "167669502405_366091400140059" ["from"]=> array(3) { ["category"]=> string(21) "Professional services" ["name"]=> string(9) "Warp Nine" ["id"]=> string(12) "167669502405" } ["message"]=> string(47) "Nu finns Warp Nine's annons på pizzakartonger!" ["story"]=> string(40) "Warp Nine shared Annonspizza AB's photo." ["story_tags"]=> array(2) { [0]=> array(1) { [0]=> array(5) { ["id"]=> string(12) "167669502405" ["name"]=> string(9) "Warp Nine" ["offset"]=> int(0) ["length"]=> int(9) ["type"]=> string(4) "page" } } [17]=> array(1) { [0]=> array(5) { ["id"]=> string(15) "182446165166120" ["name"]=> string(14) "Annonspizza AB" ["offset"]=> int(17) ["length"]=> int(14) ["type"]=> string(4) "page" } } } ["picture"]=> string(83) "http://photos-d.ak.fbcdn.net/hphotos-ak-ash4/384287_370171156393619_242673100_s.jpg" ["link"]=> string(105) "http://www.facebook.com/photo.php?fbid=370171156393619&set=a.347118762032192.78549.182446165166120&type=1" ["name"]=> string(15) "Timeline Photos" ["caption"]=> string(88) "Vi har även något att läsa då vi äter pizzan. Såhär ser kartongen ut på insidan!" ["properties"]=> array(1) { [0]=> array(3) { ["name"]=> string(2) "By" ["text"]=> string(14) "Annonspizza AB" ["href"]=> string(71) "http://www.facebook.com/pages/Annonspizza-AB/182446165166120?ref=stream" } } ["icon"]=> string(59) "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif" ["privacy"]=> array(1) { ["value"]=> string(0) "" } ["type"]=> string(5) "photo" ["status_type"]=> string(12) "shared_story" ["object_id"]=> string(15) "370171156393619" ["application"]=> array(2) { ["name"]=> string(6) "Photos" ["id"]=> string(10) "2305272732" } ["created_time"]=> string(24) "2012-10-04T21:05:55+0000" ["updated_time"]=> string(24) "2012-10-04T21:05:55+0000" ["comments"]=> array(1) { ["count"]=> int(0) } }
答案 0 :(得分:0)
啊,没关系 - 前7个键有它,最后有一组没有它,这当然使整个事情崩溃甚至没有打印前几个正确的。遗憾。
答案 1 :(得分:0)
如果$fbuser['feed']['data']
内有三个数组,而array1有一个消息键但是array2和array3没有,那么你将收到一个错误。
尝试:
foreach ($fbuser['feed']['data'] as $fbmsg){
$r .= '<tr><td class="fb_td"><img src="https://graph.facebook.com/'.$fbmsg['from']['id'].'/picture" class="fb_img"></td><td>'.
' <i>'.$fbmsg['from']['name'].'</i><br>'.
(isset($fbmsg['message'])?$fbmsg['message']:'').'</td></tr>';
}