3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input1 = ['hotels' => [ 'hotel' => [ [ "ort" => "rom", "lioc" => "inrom" ], [ "ort" => "paris", "lioc" => "inpsrisd" ], [ "ort" => "berlin", "lioc" => "inberlin" ], [ "ort" => "milano", "lioc" => "inmilano" ], [ "ort" => "paris", "lioc" => "anotherinpsrisd"], [ "ort" => "muc", "lioc" => "inmuc"] ] ]]; $input2 = ['hotels' => [ 'hotel' => [ [ "ort" => "rom", "lioc" => "inrom" ], [ "ort" => "beijing", "lioc" => "wanda" ] ] ]]; function recursiveUnique($input): array { // if the input is not an array, just return the input if (!is_array($input)) { return $input; } // check if the array is a list or an associative array else if (count($input) === 0 || array_keys($input) === range(0, count($input) - 1)) { return array_values(array_unique($input, SORT_REGULAR)); } else { foreach ($input as $key => $value) { $input[$key] = recursiveUnique($value); } return $input; } } var_dump(recursiveUnique(array_merge_recursive($input1, $input2)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XCHkn
function name:  (null)
number of ops:  13
compiled vars:  !0 = $input1, !1 = $input2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   39     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'recursiveunique'
          4        INIT_FCALL                                               'array_merge_recursive'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function recursiveunique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 32
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 41
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 21
filename:       /in/XCHkn
function name:  recursiveUnique
number of ops:  46
compiled vars:  !0 = $input, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   24     1        TYPE_CHECK                                  128  ~3      !0
          2        BOOL_NOT                                         ~4      ~3
          3      > JMPZ                                                     ~4, ->7
   25     4    >   VERIFY_RETURN_TYPE                                       !0
          5      > RETURN                                                   !0
   24     6*       JMP                                                      ->44
   28     7    >   COUNT                                            ~5      !0
          8        IS_IDENTICAL                                     ~6      ~5, 0
          9      > JMPNZ_EX                                         ~6      ~6, ->21
         10    >   INIT_FCALL                                               'array_keys'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $7      
         13        INIT_FCALL                                               'range'
         14        SEND_VAL                                                 0
         15        COUNT                                            ~8      !0
         16        SUB                                              ~9      ~8, 1
         17        SEND_VAL                                                 ~9
         18        DO_ICALL                                         $10     
         19        IS_IDENTICAL                                     ~11     $7, $10
         20        BOOL                                             ~6      ~11
         21    > > JMPZ                                                     ~6, ->32
   29    22    >   INIT_FCALL                                               'array_values'
         23        INIT_FCALL                                               'array_unique'
         24        SEND_VAR                                                 !0
         25        SEND_VAL                                                 0
         26        DO_ICALL                                         $12     
         27        SEND_VAR                                                 $12
         28        DO_ICALL                                         $13     
         29        VERIFY_RETURN_TYPE                                       $13
         30      > RETURN                                                   $13
   28    31*       JMP                                                      ->44
   32    32    > > FE_RESET_R                                       $14     !0, ->41
         33    > > FE_FETCH_R                                       ~15     $14, !1, ->41
         34    >   ASSIGN                                                   !2, ~15
   33    35        INIT_FCALL_BY_NAME                                       'recursiveUnique'
         36        SEND_VAR_EX                                              !1
         37        DO_FCALL                                      0  $18     
         38        ASSIGN_DIM                                               !0, !2
         39        OP_DATA                                                  $18
   32    40      > JMP                                                      ->33
         41    >   FE_FREE                                                  $14
   35    42        VERIFY_RETURN_TYPE                                       !0
         43      > RETURN                                                   !0
   37    44*       VERIFY_RETURN_TYPE                                       
         45*     > RETURN                                                   null

End of function recursiveunique

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
224.75 ms | 1012 KiB | 20 Q