3v4l.org

run code in 500+ PHP versions simultaneously
<?php $sample = array('a.col1','a.col2','b.col1','c.col1','c.col2','d.col5'); $new = []; foreach($sample as $value){ $arr = explode(".", $value); if(array_key_exists($arr[0],$new)){ array_push($new[$arr[0]], $arr[1]); }else{; $new[$arr[0]][] = $arr[1]; } } print_r($new );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/eYKDc
function name:  (null)
number of ops:  31
compiled vars:  !0 = $sample, !1 = $new, !2 = $value, !3 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN                                                       !1, <array>
    5     2      > FE_RESET_R                                           $6      !0, ->26
          3    > > FE_FETCH_R                                                   $6, !2, ->26
    6     4    >   INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '.'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $7      
          8        ASSIGN                                                       !3, $7
    7     9        FETCH_DIM_R                                          ~9      !3, 0
         10        ARRAY_KEY_EXISTS                                             ~9, !1
         11      > JMPZ                                                         ~10, ->20
    8    12    >   INIT_FCALL                                                   'array_push'
         13        FETCH_DIM_R                                          ~11     !3, 0
         14        FETCH_DIM_W                                          $12     !1, ~11
         15        SEND_REF                                                     $12
         16        FETCH_DIM_R                                          ~13     !3, 1
         17        SEND_VAL                                                     ~13
         18        DO_ICALL                                                     
    7    19      > JMP                                                          ->25
   10    20    >   FETCH_DIM_R                                          ~15     !3, 0
         21        FETCH_DIM_R                                          ~18     !3, 1
         22        FETCH_DIM_W                                          $16     !1, ~15
         23        ASSIGN_DIM                                                   $16
         24        OP_DATA                                                      ~18
    5    25    > > JMP                                                          ->3
         26    >   FE_FREE                                                      $6
   13    27        INIT_FCALL                                                   'print_r'
         28        SEND_VAR                                                     !1
         29        DO_ICALL                                                     
         30      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.43 ms | 2172 KiB | 16 Q