3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array( 'Europe' => 'World', 'Asia' => 'World', 'Africa' => 'World', 'France' => 'Europe', 'Poland' => 'Europe', 'Germany' => 'Europe', 'Paris' => 'France', 'Lille' => 'France', 'Warsaw' => 'Poland', 'Szczecin' => 'Poland', 'Berlin' => 'Germany', 'Gumience' => 'Szczecin' ); foreach($myArray as $key => $val) { $element = build($key, $myArray); if ($element) { $result[$element][$key] = $value; } else { $result[][$value] = array(); } } function build($needle, $haystack) { foreach($haystack as $key => $value) { if ($needle === $key OR (is_array($value) && build($needle, $value) !== false)) { return $value; } } return false; } function print_r2($val){ echo '<pre>'; print_r($val); echo '</pre>'; } print_r2($myArray); echo ('<br /><br />'); print_r2($result); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 18
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/OGoXa
function name:  (null)
number of ops:  27
compiled vars:  !0 = $myArray, !1 = $val, !2 = $key, !3 = $element, !4 = $result, !5 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   20     1      > FE_RESET_R                                       $7      !0, ->18
          2    > > FE_FETCH_R                                       ~8      $7, !1, ->18
          3    >   ASSIGN                                                   !2, ~8
   23     4        INIT_FCALL_BY_NAME                                       'build'
          5        SEND_VAR_EX                                              !2
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $10     
          8        ASSIGN                                                   !3, $10
   25     9      > JMPZ                                                     !3, ->14
   27    10    >   FETCH_DIM_W                                      $12     !4, !3
         11        ASSIGN_DIM                                               $12, !2
         12        OP_DATA                                                  !5
   25    13      > JMP                                                      ->17
   31    14    >   FETCH_DIM_W                                      $14     !4
         15        ASSIGN_DIM                                               $14, !5
         16        OP_DATA                                                  <array>
   20    17    > > JMP                                                      ->2
         18    >   FE_FREE                                                  $7
   56    19        INIT_FCALL                                               'print_r2'
         20        SEND_VAR                                                 !0
         21        DO_FCALL                                      0          
   58    22        ECHO                                                     '%3Cbr+%2F%3E%3Cbr+%2F%3E'
   60    23        INIT_FCALL                                               'print_r2'
         24        SEND_VAR                                                 !4
         25        DO_FCALL                                      0          
   61    26      > RETURN                                                   1

Function build:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
Branch analysis from position: 16
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/OGoXa
function name:  build
number of ops:  23
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2      > FE_RESET_R                                       $4      !1, ->20
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->20
          4    >   ASSIGN                                                   !3, ~5
   40     5        IS_IDENTICAL                                     ~7      !0, !3
          6      > JMPNZ_EX                                         ~7      ~7, ->16
          7    >   TYPE_CHECK                                  128  ~8      !2
          8      > JMPZ_EX                                          ~8      ~8, ->15
          9    >   INIT_FCALL_BY_NAME                                       'build'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $9      
         13        TYPE_CHECK                                  1018  ~10     $9
         14        BOOL                                             ~8      ~10
         15    >   BOOL                                             ~7      ~8
         16    > > JMPZ                                                     ~7, ->19
   42    17    >   FE_FREE                                                  $4
         18      > RETURN                                                   !2
   38    19    > > JMP                                                      ->3
         20    >   FE_FREE                                                  $4
   45    21      > RETURN                                                   <false>
   48    22*     > RETURN                                                   null

End of function build

Function print_r2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OGoXa
function name:  print_r2
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        ECHO                                                     '%3Cpre%3E'
   52     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   53     5        ECHO                                                     '%3C%2Fpre%3E'
   54     6      > RETURN                                                   null

End of function print_r2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.17 ms | 1007 KiB | 16 Q