I have a multidimensional array called $songs, which outputs the following:
Array
(
[0] => Array
(
[Michael Jackson] => Thriller
)
[1] => Array
(
[Michael Jackson] => Rock With You
)
[2] => Array
(
[Teddy Pendergrass] => Love TKO
)
[3] => Array
(
[ACDC] => Back in Black
)
)
I would like to merge the arrays which have duplicate keys, so I can get the following:
Array
(
[0] => Array
(
[Michael Jackson] => Array
(
[0] => Thriller
[1] => Rock With You
)
)
[1] => Array
(
[Teddy Pendergrass] => Love TKO
)
[2] => Array
(
[ACDC] => Back in Black
)
)
How do I do this?
Bonus points for giving me the code to output the array like:
<h2>Michael Jackson</h2>
<ul>
<li>Thriller</li>
<li>Thriller</li>
</ul>
<h2>Teddy Pendergrass</h2>
<ul>
<li>Love TKO</li>
</ul>
<h2>ACDC</h2>
<ul>
<li>Back in Black</li>
</ul>
This should do it, it's not exactly what you want but I don't see a reason why you'd need to index the resulting array numerically, and then by artist.
And you can loop the
$result
array and build your HTML like this:Which would result in a similar list that you described.