3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = <<<STR Maths Maths|Algebre Maths|Algebre|Algebre 1 Maths|Algebre|Algebre 2 Maths|Algebre|Algebre 3 Maths|Analyse Maths|Analyse|Analyse 1 Maths|Analyse|Analyse 2 Maths|Probabilité physics STR; function cleanupLines(array $lines): array { foreach ($lines as $index => $line) { if ($index > 0 && strpos($line, $lines[$index - 1]) === 0) { unset($lines[$index - 1]); } } return $lines; } function lineToArray(array $lineParts): array { if (count($lineParts) > 1) { return [$lineParts[0] => lineToArray(array_slice($lineParts, 1))]; } return $lineParts; } $lines = preg_split('/\r?\n/', $input); $lines = cleanupLines($lines); $result = array_reduce($lines, static function (array $result, string $line): array { $lineParts = explode('|', $line); $arrayPart = lineToArray($lineParts); return array_merge_recursive($result, $arrayPart); }, []); print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [Maths] => Array ( [Algebre] => Array ( [0] => Algebre 1 [1] => Algebre 2 [2] => Algebre 3 ) [Analyse] => Array ( [0] => Analyse 1 [1] => Analyse 2 ) [0] => Probabilité ) [0] => physics )

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:
107.81 ms | 406 KiB | 5 Q