array_push() w/ multi-dimensional arrays

Little puzzled about how to accomplish this task.

Have one empty master array which holds all the songs in a playlist.

$songs = array();

I want to have another array inside the $songs array called $song.

$song will contain data like: Track Name, Artist Name, Album Name, Year, Duration, etc.

Here is the generic outline what I’m looking for:

[php]$songs = array(
[0] => array(“track” => “Eyes Be Closed”,
“artist” => “Washed Out”,
“album” => “Within and Without”,
“year” => “2011”,
“duration” => “1:23”
),
[1] => array(“track” => “They Say You Won’t Come Back”,
“artist” => “Breathe Carolina”,
“album” => “Hell Is What You Make It”,
“year” => “2011”,
“duration” => “3:21”
)
);[/php]

Each of these items (track, artist, album, year, duration) are already in their own separate arrays. I would like to push the data from these arrays into one array ($song) and for each song, push it into the array ($songs).

Any guidance would be appreciated.

Thanks in advance,

Rygotype

It was actually more simple than I imagined, and I was able to accomplish my task with the usage of only one array.

Just needed to declare the empty array before my loop:

$songs = array();

Then inside my loop:
[php]$songs[] = array(“track” => $song_name,
“artist” => $song_artist,
“album” => $song_album,
“year” => $song_year,
“duration” => $song_duration
);[/php]

Result:

[code]Array
(
[0] => Array
(
[track] => Eyes Be Closed
[artist] => Washed Out
[album] => Within and Without
[year] => 2011
[duration] => 1:23
)

[1] => Array
    (
	[track] => They Say You Won't Come Back
	[artist] => Breathe Carolina
	[album] => Hell Is What You Make It
	[year] => 2011
	[duration] => 3:21
    )

)[/code]

Hope this helps someone!

-Rygotype

Sponsor our Newsletter | Privacy Policy | Terms of Service