3v4l.org

run code in 500+ PHP versions simultaneously
<?php $myarray = [ [0, 70, 19, 0], [0, 24, 14], // note missing 4th element [0, 15, 11, 0], [0, 15, 27, 0] ]; for ($i = count($myarray) - 2; $i >= 0; --$i) { // start from 2nd last subarray, and move toward the start $max = max(count($myarray[$i]), count($myarray[$i+1])); // make sure all elements are accounted for for($k = 0; $k < $max; ++$k) { // iterate and perform subtractions / declarations $myarray[$i][$k] = ($myarray[$i][$k] ?? 0) - ($myarray[$i+1][$k] ?? 0); // declare/overwrite new values as encountered } } var_export($myarray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 5
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 14
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 5
Branch analysis from position: 33
Branch analysis from position: 5
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 14
Branch analysis from position: 30
Branch analysis from position: 14
filename:       /in/XdO1X
function name:  (null)
number of ops:  37
compiled vars:  !0 = $myarray, !1 = $i, !2 = $max, !3 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    9     1        COUNT                                                ~5      !0
          2        SUB                                                  ~6      ~5, 2
          3        ASSIGN                                                       !1, ~6
          4      > JMP                                                          ->31
   10     5    >   FETCH_DIM_R                                          ~8      !0, !1
          6        COUNT                                                ~9      ~8
          7        ADD                                                  ~10     !1, 1
          8        FETCH_DIM_R                                          ~11     !0, ~10
          9        COUNT                                                ~12     ~11
         10        FRAMELESS_ICALL_2                max                 ~13     ~9, ~12
         11        ASSIGN                                                       !2, ~13
   11    12        ASSIGN                                                       !3, 0
         13      > JMP                                                          ->28
   12    14    >   FETCH_DIM_IS                                         ~18     !0, !1
         15        FETCH_DIM_IS                                         ~19     ~18, !3
         16        COALESCE                                             ~20     ~19
         17        QM_ASSIGN                                            ~20     0
         18        ADD                                                  ~21     !1, 1
         19        FETCH_DIM_IS                                         ~22     !0, ~21
         20        FETCH_DIM_IS                                         ~23     ~22, !3
         21        COALESCE                                             ~24     ~23
         22        QM_ASSIGN                                            ~24     0
         23        SUB                                                  ~25     ~20, ~24
         24        FETCH_DIM_W                                          $16     !0, !1
         25        ASSIGN_DIM                                                   $16, !3
         26        OP_DATA                                                      ~25
   11    27        PRE_INC                                                      !3
         28    >   IS_SMALLER                                                   !3, !2
         29      > JMPNZ                                                        ~27, ->14
    9    30    >   PRE_DEC                                                      !1
         31    >   IS_SMALLER_OR_EQUAL                                          0, !1
         32      > JMPNZ                                                        ~29, ->5
   16    33    >   INIT_FCALL                                                   'var_export'
         34        SEND_VAR                                                     !0
         35        DO_ICALL                                                     
         36      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
214.05 ms | 2044 KiB | 14 Q