Creating an array via foreach
<p>I'm using SimpleXML to extract images from a public feed @ Flickr. I want to put all pulled images into an array, which I've done:</p>

<pre><code>$images = array();
foreach($channel-&gt;item as $item){
    $url = $path-&gt;to-&gt;url;
    $images[] = $url;
}
</code></pre>

<p>From this I can then echo out all the images using:</p>

<pre><code>foreach($images as $image){
    //output image
}
</code></pre>

<p>I then decided I wanted to have the image title as well as the user so I assumed I would use:</p>

<pre><code>$images = array();
foreach($channel-&gt;item as $item){
    $url = $path-&gt;to-&gt;url;
    $title = $path-&gt;to-&gt;title;
    $images[$title] = $url;
}
</code></pre>

<p>I thought this would mean by using <code>$image['name of title']</code> I could output the URL for that title, but it gives an Illegal Offset Error when I run this.. and would only have the title and url, but not the user.</p>

<p>After Googling a bit I read you cannot use <code>_</code> in the array key, but I tried using:</p>

<pre><code>$normal = 'dddd';
$illegal = '  de___eee';
$li[$normal] = 'Normal';
$li[$illegal] = 'Illegal';
</code></pre>

<p>And this outputs right, ruling out <code>_</code> is illegal in array keys (..I think).</p>

<p>So now I'm really confused why it won't run, when I've used <code>print_r()</code> when playing around I've noticed some SimpleXML objects in the array, which is why I assume this is giving an error.</p>

<p>The ideal output would be an array in the format:</p>

<pre><code>$image = array( 0 =&gt; array('title'=&gt;'title of image',
                           'user'=&gt;'name of user',
                           'url' =&gt;'url of image'),
                1 =&gt; array(....)
         );
</code></pre>

<p>But I'm really stumped how I'd form this from a <code>foreach</code> loop, links to reference as well as other questions (couldn't find any) are welcome.</p>
