Access an array of objects

1

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

object(stdClass)[5]
  public 'Results' => 
    array (size=50)
      0 => 
        object(stdClass)[6]
          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 '176.200.55.211' (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
source

3 answers

1

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
1

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

$variableQueHizoVarDump->Results[{indice}]->{TuCampo};

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

    
answered by 27.09.2018 в 19:52
0

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