print_r($xml);
:
SimpleXMLElement Object
(
[groupId] => Array
(
[0] => 1
[1] => 5
)
)
in_array(1, $xml->groupId)
在这不起作用:PHP Warning: in_array() expects parameter 2 to be array, object given
print_r((array)$xml->groupId);
只打印数组的第一个元素:
Array
(
[0] => 1
)
如何正确地检查groupId
中存在的元素,没有像json_decode(json_encode($xml->groupId));
一样的hack ?
XML print_r($xml->asXML());
:
<?xml version="1.0"?>
<return>
<groupId>1</groupId>
<groupId>5</groupId>
<code>13</code>
</return>
为什么(array)$xml->groupId
....哦……哈哈:-)现在我看到问题了....由于
try
$xml = '<?xml version="1.0"?><return><groupId>1</groupId><groupId>5</groupId>
<code>13</code></return>';
$xml = simplexml_load_string($xml);
print_r($xml);
if(in_array(1, (array)$xml)) {
echo 'got it';
}else {
echo 'not get';
}