3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ ["relation" => "OR"], ["color" => 'green'], ["color" => 'yellow'], ["relation" => "AND"], ["color" => 'black'], ["color" => 'orange'], ["relation" => "OR"], ["color" => 'blue'], ["color" => 'violet'], ]; $ref = []; $result = &$ref; foreach ($input as $row) { if (key($row) === 'relation') { if ($ref) { // not the first relation encountered $ref = &$ref[]; // set $ref to point to new deeper subarray } $ref = $row; // push relation } else { $ref[] = $row; // push color into reference } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/5imCm
function name:  (null)
number of ops:  23
compiled vars:  !0 = $input, !1 = $ref, !2 = $result, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   16     2        ASSIGN_REF                                               !2, !1
   17     3      > FE_RESET_R                                       $7      !0, ->18
          4    > > FE_FETCH_R                                               $7, !3, ->18
   18     5    >   INIT_FCALL                                               'key'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $8      
          8        IS_IDENTICAL                                             $8, 'relation'
          9      > JMPZ                                                     ~9, ->15
   19    10    > > JMPZ                                                     !1, ->13
   20    11    >   FETCH_DIM_W                                      $10     !1
         12        ASSIGN_REF                                               !1, $10
   22    13    >   ASSIGN                                                   !1, !3
   18    14      > JMP                                                      ->17
   24    15    >   ASSIGN_DIM                                               !1
         16        OP_DATA                                                  !3
   17    17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $7
   28    19        INIT_FCALL                                               'var_export'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.95 ms | 1006 KiB | 15 Q