3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
25.25 ms | 405 KiB | 5 Q