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 git.master, git.master_jit, rfc.property-hooks
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 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
138.94 ms | 407 KiB | 5 Q