Note that there are some explanatory texts on larger screens.

plurals
  1. POinvalid argument supplied for foreach
    primarykey
    data
    text
    <p>I am parsing XML in PHP code and getting a warning "invalid argument supplied for foreach". Below is the XML:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;BookStore&gt; &lt;book&gt; &lt;title&gt;Computer Concepts&lt;/title&gt; &lt;auther&gt;Goerge Arthar&lt;/auther&gt; &lt;category&gt;Computer Science&lt;/category&gt; &lt;price&gt;24.00&lt;/price&gt; &lt;/book&gt; &lt;book&gt; &lt;title&gt;Algebra&lt;/title&gt; &lt;auther&gt;Mike&lt;/auther&gt; &lt;category&gt;Mathematics&lt;/category&gt; &lt;price&gt;34.00&lt;/price&gt; &lt;/book&gt; &lt;/BookStore&gt; </code></pre> <p>and using the following code:</p> <pre><code>&lt;?php $xmlDOM = new DOMDocument(); $xmlDOM-&gt;load("Books.xml"); $document = $xmlDOM-&gt;documentElement; foreach ($document-&gt;childNodes as $node) { foreach($node-&gt;childNodes as $temp) { echo $temp-&gt;nodeName."=".$temp-&gt;nodeValue."&lt;br /&gt;"; } } ?&gt; </code></pre> <p>NOTE: I get the output that I require but with a warning. It shows that array is not empty. Please see output also:</p> <pre><code>Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8 #text= title=Computer Concepts #text= auther=Goerge Arthar #text= category=Computer Science #text= price=24.00 #text= Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8 #text= title=Algebra #text= auther=Mike #text= category=Mathematics #text= price=34.00 #text= Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload