0

问这个我觉得很愚蠢,但这是怎么回事

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

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

产生我想要的确切结果,它显示了数组键'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) } }
4

2 回答 2

0

啊,没关系 - 前 7 个键有它,最后有一个缺少它,这当然使整个事情崩溃,甚至没有打印前几个正确的键。对不起。

于 2013-01-15T23:28:44.667 回答
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>';
}
于 2013-01-15T23:29:55.877 回答