Mohammed Abdellatif Mohammed Abdellatif - 29 days ago 9
PHP Question

php read from array inside class

when i use print_r for the response from API URL i got the following result:

stdClass Object(
[Messages] => Array
(
[0] => stdClass Object
(
[MessageID] => 990950058
[Recipient] => 966000000000
[Status] => Queued
)

[1] => stdClass Object
(
[MessageID] => 990950059
[Recipient] => 966500000000
[Status] => Queued
)

)

[NumberOfUnits] => 1
[Cost] => 0.00000
[Balance] => 2.89050
[TimeCreated] => 2016-11-10 14:03:49
[CurrencyCode] => SAR


)

the problem is i want to make a loop to read the values for MessageID
how i can do it?

Answer

so simple use foreach is used to loop through each key/value pair

foreach($your_variable->Messages as $row) 
 { 
   echo $row->MessageID; 
 }