$ Xml = '.. /data/news. xml'; <br/> $ QP = QP ($ XML, 'news _ root')-> Children (); </P> <p> $ arrdata = array (); <br/> $ I = 0; <br/> foreach ($ QP as $ child) <br/>{< br/> print_r ($ arrdata); <br/> echo "<br/> Hi <br/> "; <br/> unset ($ arrsub); <br/> $ arrsub = array (); <br/> array_push ($ arrdata, & $ arrsub ); <br/> print_r ($ arrdata); <br/> echo "<br/>"; <br/> // $ arrdata [] = & $ arrsub; <br/> $ child = $ child-> Children (); <br/> foreach ($ child as $ item) <br/>{< br/> $ arrsub [$ item-> tag ()] = $ item-> text (); <br/>}< br/> print_r ($ arrdata); <br/> echo "<br/>"; <br/>}
The aboveCodeNote the unset ($ arrsub) statement.
My intention is $ arrdata to parse the XML Layer 2 content.
I use array_push to press a referenced array arrsub,
Then, the arrsub operation is equivalent to modifying arrdata.
However, this is actually a problem.
It shows that the last content of arrdata is the copy of the last XML content. (My XML is empty at last, so arrdata is: [[], [], rather than correct: [[data1, data2], []
After I press arrsub into arrdata by reference,
After a loop, the statement $ arrsub = array () is encountered. After this statement is executed, one of arrdata becomes an empty array.
Therefore, unset ($ arrsub) must be removed to solve the problem.