2010-03-30 16 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) 
     .... 
     .... 

를 반복하는, 그러나 주소, 이름, deliveryStatus를 반복하지 않는 방법! 이 데이터를 가져 오는 방법을 보여줄 수 있습니까?foreach 문 :이 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

주소, 이름, 당신이

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

감사합니다 인쇄 데이터를 추출 할 수 있도록 아이 배열을 반복 할 필요가 있으므로 deliveryStatus 아이 배열에있다! 이제는 분명합니다! ;-) – ilnur777