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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  (null)
number of ops:  20
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   37     1        INIT_FCALL                                               'array_map'
   38     2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   43     3        SEND_VAL                                                 ~3
          4        SEND_VAR                                                 !0
   37     5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   45     7        INIT_FCALL                                               'print_r'
          8        SEND_VAL                                                 'Input%0A'
          9        DO_ICALL                                                 
   46    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   47    13        INIT_FCALL                                               'print_r'
         14        SEND_VAL                                                 'Output%0A'
         15        DO_ICALL                                                 
   48    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'fixprefix'
          2        FETCH_DIM_R                                      ~1      !0, 'prefix'
          3        SEND_VAL                                                 ~1
          4        DO_FCALL                                      0  $2      
          5        INIT_ARRAY                                       ~3      $2, 'prefix'
   41     6        INIT_FCALL                                               'fixnumber'
          7        FETCH_DIM_R                                      ~4      !0, 'number'
          8        SEND_VAL                                                 ~4
          9        DO_FCALL                                      0  $5      
         10        ADD_ARRAY_ELEMENT                                ~3      $5, 'number'
         11      > RETURN                                                   ~3
   43    12*     > RETURN                                                   null

End of Dynamic Function 0

Function fixprefix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  fixPrefix
number of ops:  30
compiled vars:  !0 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5E%28%5C%2B%7B1%2C2%7D%7C00%29%5Cd%2B%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        ASSIGN                                                   !0, $1
   22     7        INIT_FCALL                                               'preg_split'
          8        SEND_VAL                                                 '%2F%5CD%2F'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $3      
         11        ASSIGN                                                   !0, $3
   23    12        INIT_FCALL                                               'array_filter'
         13        SEND_VAR                                                 !0
         14        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
         15        SEND_VAL                                                 ~5
         16        DO_ICALL                                         $6      
         17        ASSIGN                                                   !0, $6
   24    18        INIT_FCALL                                               'implode'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $8      
         21        ASSIGN                                                   !0, $8
   25    22        INIT_FCALL                                               'preg_replace'
         23        SEND_VAL                                                 '%2F%5E%28%3F%210%29%2F'
         24        SEND_VAL                                                 '0'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $10     
         27        ASSIGN                                                   !0, $10
   27    28      > RETURN                                                   !0
   28    29*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BOOL_NOT                                         ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

End of function fixprefix

Function fixnumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  fixNumber
number of ops:  19
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%5CD%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        ASSIGN                                                   !0, $1
   32     6        INIT_FCALL                                               'array_filter'
          7        SEND_VAR                                                 !0
          8        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          9        SEND_VAL                                                 ~3
         10        DO_ICALL                                         $4      
         11        ASSIGN                                                   !0, $4
   33    12        INIT_FCALL                                               'implode'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 '+'
         15        DO_ICALL                                         $6      
         16        ASSIGN                                                   !0, $6
   34    17      > RETURN                                                   !0
   35    18*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uRM6S
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        BOOL_NOT                                         ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

End of function fixnumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.73 ms | 1027 KiB | 21 Q