php - Creating an array via foreach -


i'm using simplexml extract images public feed @ flickr. want put pulled images array, i've done:

$images = array(); foreach($channel->item $item){     $url = $path->to->url;     $images[] = $url; } 

from can echo out images using:

foreach($images $image){     //output image } 

i decided wanted have image title user assumed use:

$images = array(); foreach($channel->item $item){     $url = $path->to->url;     $title = $path->to->title;     $images[$title] = $url; } 

i thought mean using $image['name of title'] output url title, gives illegal offset error when run this.. , have title , url, not user.

after googling bit read cannot use _ in array key, tried using:

$normal = 'dddd'; $illegal = '  de___eee'; $li[$normal] = 'normal'; $li[$illegal] = 'illegal'; 

and outputs right, ruling out _ illegal in array keys (..i think).

so i'm confused why won't run, when i've used print_r() when playing around i've noticed simplexml objects in array, why assume giving error.

the ideal output array in format:

$image = array( 0 => array('title'=>'title of image',                            'user'=>'name of user',                            'url' =>'url of image'),                 1 => array(....)          ); 

but i'm stumped how i'd form foreach loop, links reference other questions (couldn't find any) welcome.

$images = array(); foreach ($channel->item $item){     $images[] = array(         'title' => $item->path->to->title,         'url'   => $item->path->to->url     ); }  foreach ($images $image) {     echo "title: $image[title], url: $image[url]\n"; } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -