Access an array of objects


What would be the syntax to access this answer made with var_dump ?. For example, access EmailAddress

  public 'Results' => 
    array (size=50)
      0 => 
          public 'EmailAddress' => string '[email protected]' (length=23)
          public 'ListID' => string '9c2fa2e06bc24ad62e054484f8894b9f' (length=32)
          public 'Date' => string '2018-09-27 08:45:00' (length=19)
          public 'IPAddress' => string '' (length=14)
          public 'Latitude' => float 44.417496
          public 'Longitude' => float 12.201096
          public 'City' => string 'Ravenna' (length=7)
          public 'Region' => string 'Emilia-Romagna' (length=14)
          public 'CountryCode' => string 'IT' (length=2)
          public 'CountryName' => string 'Italy' (length=5)
asked by Alex Hunter 27.09.2018 в 18:52

3 answers


Simply by placing -> , imagine that you have a foreach and when you go through it you want to get the value that is an object, well you do it like this:

foreach($datos as $dato){

  echo $dato->EmailAddress;


I hope you serve

answered by 27.09.2018 в 18:55

In the same var_dump you are indicating that it is an object, for which it should be treated as such.


If you notice Results, you access with indexes because it is mentioning that it is an array.

answered by 27.09.2018 в 19:52

Greetings to all and thanks for the help. The correct answer is this, since where I want to access is object-> array-> object

echo $result->response->Results[0]->EmailAddress

And to tour it:

foreach($result->response->Results as $item){
echo $item->EmailAddress;
answered by 28.09.2018 в 16:34