3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lines = [ 'Company 1', 'Software Engineer', 'July 2020 - Present (1 month)', 'Pretoria, Gauteng, South Africa', 'Company 2', 'CTO', 'September 2016 - Present (3 years 11 months)', 'Pretoria, South Africa' ]; function computeExperiences(array $lines): array { $experiences = []; $position = 0; while ($chunkLines = array_slice($lines, $position, 4)) { $experience = array_slice($chunkLines, 0, 3); $locationIsPresent = isset($chunkLines[3]) && preg_match('/\w+,\s\w+(?:,\s\w+)?/', $chunkLines[3]); if ($locationIsPresent) { $experience[] = $chunkLines[3]; $position += 4; } else { $position += 3; } $experiences[] = $experience; } return $experiences; } print_r($lines); print_r(computeExperiences($lines));
Output for 7.2.0 - 7.2.33, 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.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Array ( [0] => Company 1 [1] => Software Engineer [2] => July 2020 - Present (1 month) [3] => Pretoria, Gauteng, South Africa [4] => Company 2 [5] => CTO [6] => September 2016 - Present (3 years 11 months) [7] => Pretoria, South Africa ) Array ( [0] => Array ( [0] => Company 1 [1] => Software Engineer [2] => July 2020 - Present (1 month) [3] => Pretoria, Gauteng, South Africa ) [1] => Array ( [0] => Company 2 [1] => CTO [2] => September 2016 - Present (3 years 11 months) [3] => Pretoria, South Africa ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
193.86 ms | 408 KiB | 5 Q