2010-03-30 47 views
0
object(stdClass)[1] 
    public 'inbox' => 
    array 
     0 => 
     object(stdClass)[2] 
      public 'from' => string '55512351' (length=8) 
      public 'date' => string '29/03/2010' (length=10) 
      public 'time' => string '21:24:10' (length=8) 
      public 'utcOffsetSeconds' => int 3600 
      public 'recipients' => 
      array 
       0 => 
       object(stdClass)[3] 
        public 'address' => string '55512351' (length=8) 
        public 'name' => string '55512351' (length=8) 
        public 'deliveryStatus' => string 'notRequested' (length=12) 
      public 'body' => string 'This is message text.' (length=21) 
     1 => 
     object(stdClass)[4] 
      public 'from' => string '55512351' (length=8) 
      public 'date' => string '29/03/2010' (length=10) 
      public 'time' => string '21:24:12' (length=8) 
      public 'utcOffsetSeconds' => int 3600 
      public 'recipients' => 
      array 
       0 => 
       object(stdClass)[5] 
        public 'address' => string '55512351' (length=8) 
        public 'name' => string '55512351' (length=8) 
        public 'deliveryStatus' => string 'notRequested' (length=12) 
      public 'body' => string 'This is message text.' (length=21) 
     .... 
     .... 

我有这样的foreach,但它并没有遍历地址deliveryStatus!你能展示如何获得这些数据吗?的foreach:如何遍历这个

foreach ($data->inbox as $note) { 
    echo '<p>'; 
    echo 'From : ' . htmlspecialchars($note->from) . '<br />'; 
    echo 'Date : ' . htmlspecialchars($note->date) . '<br />'; 
    echo 'Time : ' . htmlspecialchars($note->time) . '<br />'; 
    echo 'Body : ' . htmlspecialchars($note->body) . '<br />'; 
} 

回答

1

地址,姓名,deliveryStatus是在孩子阵列,所以你需要遍历数组孩子要能提取数据到打印

foreach ($data->inbox as $note) { 
    echo '<p>'; 
    echo 'From : ' . htmlspecialchars($note->from) . '<br />'; 
    echo 'Date : ' . htmlspecialchars($note->date) . '<br />'; 
    echo 'Time : ' . htmlspecialchars($note->time) . '<br />'; 
    echo 'Body : ' . htmlspecialchars($note->body) . '<br />'; 

    //now iterate over the child array 
    foreach ($note->recipients as $recipient) { 
     echo 'x : ' . htmlspecialchars($recipient->address) . '<br />'; 
     echo 'y : ' . htmlspecialchars($recipient->name) . '<br />'; 
     echo 'z : ' . htmlspecialchars($recipient->$recipient->address) . '<br />'; 
    } 
} 
+0

谢谢!现在很清楚! ;-) – ilnur777 2010-03-30 08:41:07