2015-06-29 59 views
1

我想通過這個數組迭代通過http://2of1.com/zee/ZEES%20SMS%20SERVICE.html並提取數據。迭代通過陣列和提取數據

我用:

foreach ($graphObject['data'] as $key => $value){ 
        $string = $value->message; 
        $link = $value->actions[0]->link; 
        $pic = $value->picture; 
        $post_id = $value->id; 
} 

但它不再工作i之後加入一第二源到所述陣列。

當我嘗試:

foreach ($graphObject as $key => $value){ 
         $string = $value->data[0]->message; 
         $link = $value->data[0]->actions[0]->link; 
         $pic = $value->data[0]->picture; 
         $post_id = $value->data[0]->id; 

我得到的只有從數據中的第一項值[0],它不通過所有的數據迭代。我需要的是來自數據[0]數據[1]數據[2]數據[3] ...等等的數據...請幫助。謝謝!

+0

var_export的'輸出()'是更容易比的'的print_r()'擺弄。 – VolkerK

回答

0

大概就像

foreach ($graphObject as $keyEntry => $entry){ 
    foreach($entry->data as $data) { 
     echo $data->picture, "<br />\r\n"; 
     foreach($data->actions as $action) { 
      echo $action->link, "<br />\r\n"; 
+0

謝謝。這就是訣竅! –