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
Post a Comment