print_r($p->attachments)
产生:
Array
(
[0] => stdClass Object
(
[id] => ...
[url] => http://...png
[slug] => ...
[title] => ...
[description] => ...
[caption] => ...
[parent] => ...
[mime_type] => image/png
[images] => ...
(
)
)
)
我希望访问url
字段中的值
print_r($p->attachments[0]->url)
检索 url,但也会产生:Undefined offset: 0
现在我可以通过调用来抑制错误print_r(@$p->attachments[0]->url)
,但是有没有解决这个问题的正确方法?
我无法修改 $p 对象。
编辑:
如建议的那样,这是来自 Var_dump($p->attachments) 的响应
array(1) {
[0]=>
object(stdClass)#322 (9) {
["id"]=>
int(1814)
["url"]=>
string(76) "..."
["slug"]=>
string(34) "..."
["title"]=>
string(34) "..."
["description"]=>
string(0) ""
["caption"]=>
string(53) "..."
["parent"]=>
int(1811)
["mime_type"]=>
string(9) "image/png"
["images"]=>
array(0) {
}
}
}