Alessandro Alessandro - 2 days ago 4
PHP Question

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@domain.com"
}
}


how do i access the email part with PHP

Answer

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.

Comments