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 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Fatal error: Uncaught TypeError: implode(): Argument #1 ($separator) must be of type string, array given in /in/uRM6S:33 Stack trace: #0 /in/uRM6S(33): implode(Array, ' ') #1 /in/uRM6S(41): fixNumber(Array) #2 [internal function]: {closure:/in/uRM6S:38}(Array) #3 /in/uRM6S(37): array_map(Object(Closure), Array) #4 {main} thrown in /in/uRM6S on line 33
Process exited with code 255.
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.
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28
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.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
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(43): array_map(Object(Closure), Array) #4 {main} thrown in /in/uRM6S on line 33
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /in/uRM6S on line 33 Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /in/uRM6S on line 33 Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /in/uRM6S on line 33 Input Array ( [0] => Array ( [prefix] => +49-6151 [number] => 8844-057 ) [1] => Array ( [prefix] => 0049-6151 [number] => 8844-057 ) [2] => Array ( [prefix] => ++49 06151 [number] => 8844-057 ) ) Output Array ( [0] => Array ( [prefix] => 06151 [number] => 8844 057 ) [1] => Array ( [prefix] => 06151 [number] => 8844 057 ) [2] => Array ( [prefix] => 06151 [number] => 8844 057 ) )
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Input Array ( [0] => Array ( [prefix] => +49-6151 [number] => 8844-057 ) [1] => Array ( [prefix] => 0049-6151 [number] => 8844-057 ) [2] => Array ( [prefix] => ++49 06151 [number] => 8844-057 ) ) Output Array ( [0] => Array ( [prefix] => 06151 [number] => 8844 057 ) [1] => Array ( [prefix] => 06151 [number] => 8844 057 ) [2] => Array ( [prefix] => 06151 [number] => 8844 057 ) )

preferences:
190.69 ms | 417 KiB | 5 Q