[英]php SimpleXml & arrays issue
When I print_r($var)
I get the result below. 当我
print_r($var)
我得到下面的结果。
SimpleXMLElement Object
(
[SEND_FILE] => SimpleXMLElement Object
(
[FILEID] => 123
[GUID] => 456
[SUMMARY] => SimpleXMLElement Object
(
[NB_PAYMENTS] => 1
)
)
)
How can I get the value of the FILEID element in a variable? 如何获取变量中FILEID元素的值? If I do
如果我做
print $result->SEND_FILE->FILEID[0]
then I just get the number - what I want, no mention of a SimpleXML Object. 然后我就得到数字-我想要的,没有提及SimpleXML对象。 But if I put this variable in an array, as such
但是如果我把这个变量放在数组中
$res['file_id'] = $result->SEND_FILE->FILEID[0]
and then print_r($res)
I get: 然后我得到
print_r($res)
:
Array
(
[file_id] => SimpleXMLElement Object
(
[0] => 307466
)
)
How can I get it to remove the [0] / SimpleXMLElement Object
? 如何获取删除
[0] / SimpleXMLElement Object
?
这看起来不太优雅,但是请尝试将结果强制转换为整数(如果类型已知):
$res['file_id'] = (int)$result->SEND_FILE->FILEID[0]
Why do you append the [0]
at the end? 为什么在末尾附加
[0]
? You dont need that. 您不需要那。 You should simply do
你应该做
print $result->SEND_FILE->FILEID;
And that should be enough. 这样就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.