3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ [ "prefix" => "+49-6151", "number" => "8844-057", ], [ "prefix" => "0049-6151", "number" => "8844-057", ], [ "prefix" => "++49 06151", "number" => "8844-057", ], ]; function fixPrefix($prefix) { $prefix = preg_replace("/^(\+{1,2}|00)\d+/", '', $prefix); $prefix = preg_split("/\D/", $prefix); $prefix = array_filter($prefix, function($i) {return !!$i;}); $prefix = implode($prefix); $prefix = preg_replace("/^(?!0)/", "0", $prefix); return $prefix; } function fixNumber($number) { $number = preg_split("/\D/", $number); $number = array_filter($number, function($i) {return !!$i;}); $number = implode($number, " "); return $number; } $output = array_map( function($i) { return [ "prefix" => fixPrefix($i["prefix"]), "number" => fixNumber($i["number"]), ]; }, $input); print_r("Input\n"); print_r($input); print_r("Output\n"); print_r($output);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/uRM6S:33 Stack trace: #0 /in/uRM6S(33): implode(Array, ' ') #1 /in/uRM6S(41): fixNumber(Array) #2 [internal function]: {closure}(Array) #3 /in/uRM6S(37): array_map(Object(Closure), Array) #4 {main} thrown in /in/uRM6S on line 33
Process exited with code 255.

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