3v4l.org

run code in 300+ PHP versions simultaneously
<?php $og=array(); $og[] = array('a'=>'cat', 'b'=>'beer', 'c'=>'wood'); $og[] = array('a'=>'cat', 'b'=>'beer', 'c'=>'bamboo'); $og[] = array('a'=>'cat', 'b'=>'beer', 'c'=>'concrete'); //var_dump($og); $new_array = array(); foreach($og as $parr=>$carr) { foreach($carr as $key=>$value) { if(!array_key_exists($key,$new_array)) { $new_array[$key] = $value; }else if(!in_array($value,$new_array)) { if(is_array($new_array[$key])) { array_push($new_array[$key],$value); } else { $currentVal = $new_array[$key]; $new_array[$key] = array($key=>$currentVal); array_push($new_array[$key],$value); } } } } var_dump($new_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 48
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 48
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 46
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 46
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 45
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 45
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 46
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/JbOtd
function name:  (null)
number of ops:  53
compiled vars:  !0 = $og, !1 = $new_array, !2 = $carr, !3 = $parr, !4 = $value, !5 = $key, !6 = $currentVal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  <array>
    4     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  <array>
    5     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  <array>
    7     7        ASSIGN                                                   !1, <array>
    8     8      > FE_RESET_R                                       $12     !0, ->48
          9    > > FE_FETCH_R                                       ~13     $12, !2, ->48
         10    >   ASSIGN                                                   !3, ~13
    9    11      > FE_RESET_R                                       $15     !2, ->46
         12    > > FE_FETCH_R                                       ~16     $15, !4, ->46
         13    >   ASSIGN                                                   !5, ~16
   10    14        ARRAY_KEY_EXISTS                                 ~18     !5, !1
         15        BOOL_NOT                                         ~19     ~18
         16      > JMPZ                                                     ~19, ->20
   11    17    >   ASSIGN_DIM                                               !1, !5
         18        OP_DATA                                                  !4
   10    19      > JMP                                                      ->45
   12    20    >   INIT_FCALL                                               'in_array'
         21        SEND_VAR                                                 !4
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $21     
         24        BOOL_NOT                                         ~22     $21
         25      > JMPZ                                                     ~22, ->45
   13    26    >   FETCH_DIM_R                                      ~23     !1, !5
         27        TYPE_CHECK                                  128          ~23
         28      > JMPZ                                                     ~24, ->35
   14    29    >   INIT_FCALL                                               'array_push'
         30        FETCH_DIM_W                                      $25     !1, !5
         31        SEND_REF                                                 $25
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                                 
   13    34      > JMP                                                      ->45
   16    35    >   FETCH_DIM_R                                      ~27     !1, !5
         36        ASSIGN                                                   !6, ~27
   17    37        INIT_ARRAY                                       ~30     !6, !5
         38        ASSIGN_DIM                                               !1, !5
         39        OP_DATA                                                  ~30
   18    40        INIT_FCALL                                               'array_push'
         41        FETCH_DIM_W                                      $31     !1, !5
         42        SEND_REF                                                 $31
         43        SEND_VAR                                                 !4
         44        DO_ICALL                                                 
    9    45    > > JMP                                                      ->12
         46    >   FE_FREE                                                  $15
    8    47      > JMP                                                      ->9
         48    >   FE_FREE                                                  $12
   24    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !1
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.26 ms | 1017 KiB | 16 Q