3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "S10.G00.00.001,'www.mywebsite.com'", "S10.G00.00.002,'Company name'", "S10.G00.00.003,'v2.01'", "S10.G00.01.001,'492484944'", "S10.G00.01.002,'00029'", "S10.G00.01.003,'First name'", "S10.G00.01.004,'120 R CHARLES'", "S10.G00.01.005,'92200'", "S10.G00.02.001,'01'", "S10.G00.02.002,'first name'", "S10.G00.02.004,'email@gmail.com'", "S10.G00.02.005,'0750000000'", "S20.G00.05.001,'01'", "S20.G00.05.002,'01'", "S20.G00.05.003,'11'", "S20.G00.05.004,'5'", "S20.G00.05.010,'01'", "S10.G00.01.001,'492484944'", "S10.G00.01.002,'00029'", "S10.G00.01.003,'Last name'" ]; $result = []; $previousKey = null; $index = -1; foreach ($arr as $item) { $currentKey = substr($item, 0, 10); if ($previousKey !== $currentKey) { $index++; $previousKey = $currentKey; } $result[$index][$currentKey][] = $item; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 21
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/2PeAj
function name:  (null)
number of ops:  26
compiled vars:  !0 = $arr, !1 = $result, !2 = $previousKey, !3 = $index, !4 = $item, !5 = $currentKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   26     1        ASSIGN                                                   !1, <array>
   27     2        ASSIGN                                                   !2, null
   28     3        ASSIGN                                                   !3, -1
   30     4      > FE_RESET_R                                       $10     !0, ->21
          5    > > FE_FETCH_R                                               $10, !4, ->21
   31     6    >   INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !4
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 10
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !5, $11
   32    12        IS_NOT_IDENTICAL                                         !2, !5
         13      > JMPZ                                                     ~13, ->16
   33    14    >   PRE_INC                                                  !3
   34    15        ASSIGN                                                   !2, !5
   37    16    >   FETCH_DIM_W                                      $16     !1, !3
         17        FETCH_DIM_W                                      $17     $16, !5
         18        ASSIGN_DIM                                               $17
         19        OP_DATA                                                  !4
   30    20      > JMP                                                      ->5
         21    >   FE_FREE                                                  $10
   40    22        INIT_FCALL                                               'print_r'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.41 ms | 1011 KiB | 15 Q