使用嵌套对象访问数组

时间:2016-12-01 05:06:06

标签: php

我有一个api包装器我正在使用返回类似这样的东西

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

如何使用PHP访问电子邮件部分

1 个答案:

答案 0 :(得分:2)

将您的API返回数据转换为数组。

例如,您要在$result变量中保存API返回的数据。把它投射到数组中。

$arrayResult = (array) $result;

echo $arrayResult[0]->email;

试试这个。