<?php
$songs = [
['Michael Jackson' => 'Thriller'],
['Michael Jackson' => 'Rock With You'],
['Teddy Pendergrass' => 'Love TKO'],
['ACDC' => 'Back in Black']
];
$result = array_merge_recursive(...$songs);
var_export($result);
echo "\n---\n";
$template = <<<HTML
<h2>%s</h2>
<ul>
<li>%s</li>
</ul>
HTML;
foreach ($result as $artist => $songs) {
printf(
$template,
$artist,
implode('</li><li>', (array)$songs)
);
}
- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.26, 8.4.1 - 8.4.13
- array (
'Michael Jackson' =>
array (
0 => 'Thriller',
1 => 'Rock With You',
),
'Teddy Pendergrass' => 'Love TKO',
'ACDC' => 'Back in Black',
)
---
<h2>Michael Jackson</h2>
<ul>
<li>Thriller</li><li>Rock With You</li>
</ul>
<h2>Teddy Pendergrass</h2>
<ul>
<li>Love TKO</li>
</ul>
<h2>ACDC</h2>
<ul>
<li>Back in Black</li>
</ul>
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
'Michael Jackson' =>
array (
0 => 'Thriller',
1 => 'Rock With You',
),
'Teddy Pendergrass' => 'Love TKO',
'ACDC' => 'Back in Black',
)
---
<h2>Michael Jackson</h2>
<ul>
<li>Thriller</li><li>Rock With You</li>
</ul>
<h2>Teddy Pendergrass</h2>
<ul>
<li>Love TKO</li>
</ul>
<h2>ACDC</h2>
<ul>
<li>Back in Black</li>
</ul>
preferences:
112.89 ms | 409 KiB | 5 Q