@ 2022-04-02T13:08:01Z <?php
$songs = [
['title' => 'A Change Is Gonna Come'],
['title' => 'A Day In The Life'],
['title' => 'Be My Baby'],
['title' => 'Best Of My Love'],
['title' => 'Billie Jean'],
['title' => 'Bohemian Rhapsody'],
['title' => 'Born To Run'],
['title' => 'Bridge Over Troubled Water'],
['title' => 'Creep'],
['title' => 'Dancing In The Street'],
['title' => 'Dancing Queen'],
['title' => 'Every Breath You Take'],
['title' => 'Family Affair'],
['title' => 'Gimme Shelter'],
['title' => 'God Only Knows'],
['title' => 'God Save The Queen'],
['title' => 'Good Vibrations'],
['title' => 'Hallelujah'],
['title' => 'Heartbreak Hotel'],
['title' => 'Hey Jude'],
['title' => 'Hotel California'],
['title' => 'I Cant Get No Satisfaction'],
['title' => 'I Will Always Love You'],
['title' => 'Imagine'],
['title' => 'Jonny B Good'],
['title' => 'Life On Mars?'],
['title' => 'Like A Rolling Stone'],
['title' => 'Live Forever'],
['title' => 'London Calling'],
['title' => 'My Generation'],
['title' => 'No Woman No Cry'],
['title' => 'One'],
['title' => 'Over The Rainbow'],
['title' => 'Papas Got A Brand New Bag'],
['title' => 'Purple Haze'],
['title' => 'Respect'],
['title' => 'River Deep Mountain High'],
['title' => 'Smells Like Teen Spirit'],
['title' => 'Stairway To Heaven'],
['title' => 'Stand By Me'],
['title' => 'Sultans Of Swing'],
['title' => 'Sweet Child O Mine'],
['title' => 'The Twist'],
['title' => 'Waterloo Sunset'],
['title' => 'Whatd I Say'],
['title' => 'Whats Goin On'],
['title' => 'When Doves Cry'],
['title' => 'Yesterday'],
['title' => 'Your Song'],
['title' => 'Youve Lost That Lovin Feeling'],
];
// Group the songs by initial letter:
$grouped = [];
foreach($songs as $song) {
$initial = $song['title'][0];
$grouped[$initial][] = $song;
}
// Divide into two sections (as number of alphabets / 2):
list($left, $right) = array_chunk($grouped, ceil(count($grouped) / 2), true);
// Function to output column:
function print_songs(array $songs) {
$html = '';
foreach($songs as $letter => $songsByLetter) {
$html .= "\n" . $letter . "\n";
foreach($songsByLetter as $song) {
$html .= $song['title'] . "\n";
}
}
return $html;
}
$left_column = print_songs($left);
$right_column = print_songs($right);
echo <<<SONGS
--------
{$left_column}
--------
{$right_column}
--------
SONGS;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.4.0 - 7.4.33 , 8.0.1 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 --------
A
A Change Is Gonna Come
A Day In The Life
B
Be My Baby
Best Of My Love
Billie Jean
Bohemian Rhapsody
Born To Run
Bridge Over Troubled Water
C
Creep
D
Dancing In The Street
Dancing Queen
E
Every Breath You Take
F
Family Affair
G
Gimme Shelter
God Only Knows
God Save The Queen
Good Vibrations
H
Hallelujah
Heartbreak Hotel
Hey Jude
Hotel California
I
I Cant Get No Satisfaction
I Will Always Love You
Imagine
J
Jonny B Good
--------
L
Life On Mars?
Like A Rolling Stone
Live Forever
London Calling
M
My Generation
N
No Woman No Cry
O
One
Over The Rainbow
P
Papas Got A Brand New Bag
Purple Haze
R
Respect
River Deep Mountain High
S
Smells Like Teen Spirit
Stairway To Heaven
Stand By Me
Sultans Of Swing
Sweet Child O Mine
T
The Twist
W
Waterloo Sunset
Whatd I Say
Whats Goin On
When Doves Cry
Y
Yesterday
Your Song
Youve Lost That Lovin Feeling
-------- preferences:dark mode live preview ace vim emacs key bindings
122.45 ms | 409 KiB | 5 Q