Php 从xmlparser访问xml属性
我有一个可以解析的XMLPhp 从xmlparser访问xml属性,php,xml,xml-parsing,Php,Xml,Xml Parsing,我有一个可以解析的XML $response = new SimpleXMLElement($output); 它返回以下内容: SimpleXMLElement对象([meta]=>SimpleXMLElement对象([status]=>ok[statuscode]=>100[message]=>SimpleXMLElement对象())[data]=>SimpleXMLElement对象()) 我尝试返回状态码(100),其中有许多变化: $response->$meta[0]['
$response = new SimpleXMLElement($output);
它返回以下内容:
SimpleXMLElement对象([meta]=>SimpleXMLElement对象([status]=>ok[statuscode]=>100[message]=>SimpleXMLElement对象())[data]=>SimpleXMLElement对象())
我尝试返回状态码(100),其中有许多变化:
$response->$meta[0]['statuscode'];
还是这个
$response->$meta[0]->statuscode;
但是我没有找到返回值的正确语法。这里缺少什么?示例代码中没有变量
$meta
由于只有一个SimpleXmlElement,因此可以使用statuscode属性
$statusCode = (string)$response->meta->statuscode;
如果有更多元素,可以使用索引0来获取第一个元素
$response = new SimpleXMLElement($output);
$statusCode = (string)$response->meta[0]->statuscode;
echo $statusCode;
输出
100
谢谢你给我解释:)