当我使用函数时,我有一个名为$ results的数组:
print_r($results);
Run Code Online (Sandbox Code Playgroud)
我得到以下内容.
Array
(
[0] => ProfileElement Object
(
[name] => John thomson
[email] => johnt@gmail.com
[Bio] => 20 years of engineering expertise
[url] => http://twitter.com
)
)
Run Code Online (Sandbox Code Playgroud)
我的目标是分别回显[name] [email] [Bio] [url]值.但是当我在php中编写以下代码时,我没有得到任何值?
echo $results[0]["ProfileElement Objects"]["Bio"];
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么?这不是数组中的数组吗?
看来数组元素包含一个对象,而不是另一个数组.要访问object属性,请使用->运算符:
echo $results[0]->Bio;
Run Code Online (Sandbox Code Playgroud)
你很亲密
echo $results[0]->bio;
Run Code Online (Sandbox Code Playgroud)
可能是你想要的.$result[0]是一个对象.
此外,根据可见性,您可能需要使用getter方法.