php - simpleXMLElement attributes and foreach -
php - simpleXMLElement attributes and foreach -
if run in debugger, programme performs 2 iterations correctly, , infinite loop. if exchange line foreach, works correctly. why?
test.xml:
<?xml version="1.0" encoding="utf-8"?> <response result="0"> <reports> <get count="2"> <row a="first" b="second" comment="test" c=""/> <row a="first1" b="second2" comment="test2" c=""/> </get> </reports> </response>
php:
$xml = simplexml_load_file('test.xml'); $rows = $xml->xpath('reports/get/row'); foreach($rows $row){ $item = []; $attr = $row->attributes(); print_r($attr); $i = 0; foreach($attr $key => $value){ //foreach($row->attributes() $key => $value){ $item[$key] = (string) $value; $i++; } $arr[] = $item; } homecoming $arr;
php xml simplexml
Comments
Post a Comment