I am generating an php array and then converting it to a xml playlist. converting array to xml is no problem, but i am having problem generating the array. I am getting data from DB and want to use it. My code is like bellow-
$songs2008 = get_data("musics", "where year='2008'");
$mysongs = array();
foreach($songs2008 as $k1=>$v1){
$entry = array(
"url"=>"songs/main_songs/".$v1[file_name],
"songname"=>$v1[song_title],
"artist"=>$v1[artist]
);
array_push($mysongs, $entry);
}
and the array is -
$array = array(
"settings"=>array(
"width"=>"316",
"songs"=>array(
"albumArt"=>array(
"url"=>"songs/2008.jpg",
"entries"=>array(
"entry"=>$mysongs['0'],
"entry"=>$mysongs['1'],
"entry"=>$mysongs['2'],
----------------------
----------------------
)
)
)
);
Its not working at the entries. the array key is sam开发者_如何学运维e(entry); so only one showing. is there any solution? any other way to do it? please help.
It's because you can't use 'entry' as an index more than once. Try:
"entries" => $mysongs
@see: http://php.net/manual/de/language.types.array.php for further reading an php arrays
But be carefull, you'll propably be running into some problems creating your xml code when using this. For I would bet that you are using the array keys as tag names!
Don't name your array key for "entry"
$array = array(
"settings"=>array(
"width"=>"316",
"songs"=>array(
"albumArt"=>array(
"url"=>"songs/2008.jpg",
"entries"=>array(
$mysongs['0'],
$mysongs['1'],
$mysongs['2'],
----------------------
----------------------
)
)
)
);
精彩评论