Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping through SimpleXMLElement Object works only in 2 steps
    primarykey
    data
    text
    <p>I've got a SimpleXMLElement for which I read in a XML file using curl. Trying to get the values out of it I seem to need to use a nested foreach, but in a similar situation I was able to do this in one go. Now I'm really curious why this isn't working:</p> <p>Its the delicious RSS feed; </p> <pre><code>SimpleXMLElement Object ( [title] =&gt; Delicious/chrisvdberge [link] =&gt; http://www.delicious.com/chrisvdberge [description] =&gt; bookmarks posted by chrisvdberge [item] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [title] =&gt; Diagrammr [pubDate] =&gt; Thu, 06 May 2010 12:40:07 +0000 [guid] =&gt; http://www.delicious.com/url/2fc2ed0e870ec9d001b645dfaed0e771#chrisvdberge [link] =&gt; http://www.diagrammr.com/ [comments] =&gt; http://www.delicious.com/url/2fc2ed0e870ec9d001b645dfaed0e771 [source] =&gt; chrisvdberge's bookmarks [category] =&gt; Array ( [0] =&gt; tagthis [1] =&gt; visualization [2] =&gt; diagrams ) ) [1] =&gt; SimpleXMLElement Object ( [title] =&gt; Ignite Toronto 2: Ryan Coleman - Designing for visual efficiency on Vimeo [pubDate] =&gt; Mon, 18 Jan 2010 08:05:06 +0000 [guid] =&gt; http://www.delicious.com/url/9a0de307f3f37baaa25ad20b4dbc4537#chrisvdberge [link] =&gt; http://vimeo.com/8317770 [comments] =&gt; http://www.delicious.com/url/9a0de307f3f37baaa25ad20b4dbc4537 [source] =&gt; chrisvdberge's bookmarks [category] =&gt; Array ( [0] =&gt; tagthis [1] =&gt; vizthink ) ) </code></pre> <p>etc. </p> <p>I can access all the links by using a nested foreach:</p> <pre><code>foreach ($delicious_res as $item) { foreach ($item-&gt;item as $entry){ echo $entry-&gt;link."&lt;br /&gt;"; } } </code></pre> <p>But I don't understand why I cant use this (which I can in another situation)</p> <pre><code>foreach ($delicious_res-&gt;item as $item) { echo $entry-&gt;link."&lt;br /&gt;"; } </code></pre> <p>I really like to understand why in order to get a better understanding of SimpleXML in general ;) </p>
    singulars
    1. This table or related slice is empty.
    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