Alessandro
Alessandro

Reputation: 385

Accessing array with nested objects

I have an api wrapper i am using that returns something like this

object(stdClass)#7 (1) {
  [0]=>
  object(stdClass)#6 (2) {
    ["contactId"]=>
    string(2) "nV"
    ["email"]=>
    string(31) "[email protected]"
  }
}

how do i access the email part with PHP

Upvotes: 0

Views: 50

Answers (1)

Mahfuzul Alam
Mahfuzul Alam

Reputation: 3157

Cast your API returned data to an array.

For example you are saving API returned data in $result variable. Cast it to an array.

$arrayResult = (array) $result;

echo $arrayResult[0]->email;

Try this.

Upvotes: 2

Related Questions