3v4l.org

run code in 500+ PHP versions simultaneously
<?php function print_line(string $output): void { echo $output . PHP_EOL; } function normalize_property_keys(array $props, ?array $matchers = []): array { $normalized = []; foreach ($props as $key => $value) { $matched_key = $matchers[$key] ?? null; if ($matched_key) { $normalized[$matched_key] = $value; } else { $norm_key = preg_replace('/[-\s]+/', '', $key); $normalized[$norm_key] = $value; } } return $normalized; } $keys = [ 'align' => 'alignment', 'col' => 'color', 'colour' => 'color', ]; $tests = [ 'align' => 1, 'col' => 2, 'test-key' => 3, 'test_new_key' => 4, ]; print_line("Original Array"); print_r($tests); print_line(""); print_line("Normalized Array"); print_r(normalize_property_keys($tests, $keys));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8VbS9
function name:  (null)
number of ops:  22
compiled vars:  !0 = $keys, !1 = $tests
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                       !0, <array>
   26     1        ASSIGN                                                       !1, <array>
   34     2        INIT_FCALL                                                   'print_line'
          3        SEND_VAL                                                     'Original+Array'
          4        DO_FCALL                                          0          
   35     5        INIT_FCALL                                                   'print_r'
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                                     
   36     8        INIT_FCALL                                                   'print_line'
          9        SEND_VAL                                                     ''
         10        DO_FCALL                                          0          
   37    11        INIT_FCALL                                                   'print_line'
         12        SEND_VAL                                                     'Normalized+Array'
         13        DO_FCALL                                          0          
   38    14        INIT_FCALL                                                   'print_r'
         15        INIT_FCALL                                                   'normalize_property_keys'
         16        SEND_VAR                                                     !1
         17        SEND_VAR                                                     !0
         18        DO_FCALL                                          0  $8      
         19        SEND_VAR                                                     $8
         20        DO_ICALL                                                     
         21      > RETURN                                                       1

Function print_line:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8VbS9
function name:  print_line
number of ops:  4
compiled vars:  !0 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
    3     1        CONCAT                                               ~1      !0, '%0A'
          2        ECHO                                                         ~1
    4     3      > RETURN                                                       null

End of function print_line

Function normalize_property_keys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/8VbS9
function name:  normalize_property_keys
number of ops:  25
compiled vars:  !0 = $props, !1 = $matchers, !2 = $normalized, !3 = $value, !4 = $key, !5 = $matched_key, !6 = $norm_key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      <array>
    7     2        ASSIGN                                                       !2, <array>
    8     3      > FE_RESET_R                                           $8      !0, ->20
          4    > > FE_FETCH_R                                           ~9      $8, !3, ->20
          5    >   ASSIGN                                                       !4, ~9
    9     6        FETCH_DIM_IS                                         ~11     !1, !4
          7        COALESCE                                             ~12     ~11
          8        QM_ASSIGN                                            ~12     null
          9        ASSIGN                                                       !5, ~12
   10    10      > JMPZ                                                         !5, ->14
   11    11    >   ASSIGN_DIM                                                   !2, !5
         12        OP_DATA                                                      !3
   10    13      > JMP                                                          ->19
   13    14    >   FRAMELESS_ICALL_3                preg_replace        ~15     '%2F%5B-%5Cs%5D%2B%2F', ''
         15        OP_DATA                                                      !4
         16        ASSIGN                                                       !6, ~15
   14    17        ASSIGN_DIM                                                   !2, !6
         18        OP_DATA                                                      !3
    8    19    > > JMP                                                          ->4
         20    >   FE_FREE                                                      $8
   17    21        VERIFY_RETURN_TYPE                                           !2
         22      > RETURN                                                       !2
   18    23*       VERIFY_RETURN_TYPE                                           
         24*     > RETURN                                                       null

End of function normalize_property_keys

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.41 ms | 1331 KiB | 20 Q