2013-01-15 49 views
0

我覺得相當愚蠢的問這個,但它是如何,這數組鍵已被訪問

 foreach ($fbuser['feed']['data'] as $fbmsg){ 

      var_dump($fbmsg['message']); 
      die; 

產生精確的結果,我想,它讓我看到陣列關鍵的內容「信息」 ...

...而這會引發錯誤說明該密鑰「信息」是未定義...

 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,清楚地含有[「消息」]關鍵...

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) } } 
+2

你的第一個代碼片段只檢查的第一個元素在'$ fbuser' [ '飼料'] [ '數據']',而第二檢查每一個元素。 –

+0

是的,意識到這一點。不過謝謝。睡覺的時間我猜=) –

回答

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>'; 
} 
0

啊,沒關係 - 第7把鑰匙了吧,有最終一組,缺乏它,這當然取得了整個事情的碰撞,甚至沒有打印的第一對夫婦的正確的人的。抱歉。