3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parse(array $lines): array { $result = []; foreach ($lines as $line) { $split = explode(': ', $line, 2); switch ($split[0]) { case 'file': unset($ref); $ref = [null, null, null]; $result[] = &$ref; break; case 'Artist': $ref[0] = $split[1]; break; case 'Album': $ref[1] = $split[1]; break; case 'Title': $ref[2] = $split[1]; break; } } return $result; } $array = [ 'MPD 0.23.5', 'file: Blondie/Parallel_Lines/12_Just_Go_Away.flac', 'Last-Modified: 2016-06-05T17:15:07Z', 'Format: 44100:16:2', 'Album: Parallel Lines', 'AlbumArtist: Blondie', 'Artist: Blondie', 'Composer: Debbie Harry', 'Date: 1978', 'Genre: Rock', 'Title: Just Go Away', 'Track: 12', 'Time: 214', 'duration: 213.800', 'Pos: 0', 'Id: 745', 'file: Blondie/Parallel_Lines/13_Once_I_Had_a_Love-aka_The_Disco_Song-1978_version-.flac', 'Last-Modified: 2016-06-05T17:15:01Z', 'Format: 44100:16:2', 'Album: Parallel Lines', 'AlbumArtist: Blondie', 'Artist: Blondie', 'Composer: Chris Stein; Debbie Harry', 'Date: 1978', 'Genre: Rock', 'Title: Once I Had a Love (aka The Disco Song) (1978 version)', 'Track: 13', 'Time: 198', 'duration: 198.000', 'Pos: 1', 'Id: 746', 'file: Blondie/Parallel_Lines/14_Bang_a_Gong-Get_It_On-live-.flac', 'Last-Modified: 2016-06-05T17:15:03Z', 'Format: 44100:16:2', 'Album: Parallel Lines', 'AlbumArtist: Blondie', 'Artist: Blondie', 'Composer: Marc Bolan', 'Date: 1978', 'Genre: Rock', 'Title: Bang a Gong (Get It On) (live)', 'Track: 14', 'Time: 330', 'duration: 330.293', 'Pos: 2', 'Id: 747', '' ]; var_export(parse($array));
Output for 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
array ( 0 => array ( 0 => 'Blondie', 1 => 'Parallel Lines', 2 => 'Just Go Away', ), 1 => array ( 0 => 'Blondie', 1 => 'Parallel Lines', 2 => 'Once I Had a Love (aka The Disco Song) (1978 version)', ), 2 => array ( 0 => 'Blondie', 1 => 'Parallel Lines', 2 => 'Bang a Gong (Get It On) (live)', ), )

preferences:
77.39 ms | 407 KiB | 5 Q