3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ['x', 'y', 'z']; $mask = 5; $count = count($arr); $mask &= pow(2, $count) - 1; $offset = $count - 1; $result = []; foreach ($arr as $k => $v) { var_dump($offset, $k); if ($mask >> ($offset - $k)) { $result[] = $v; } } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/n3S61
function name:  (null)
number of ops:  31
compiled vars:  !0 = $arr, !1 = $mask, !2 = $count, !3 = $offset, !4 = $result, !5 = $v, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 5
    6     2        COUNT                                            ~9      !0
          3        ASSIGN                                                   !2, ~9
    7     4        INIT_FCALL                                               'pow'
          5        SEND_VAL                                                 2
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $11     
          8        SUB                                              ~12     $11, 1
          9        ASSIGN_OP                                    10          !1, ~12
    8    10        SUB                                              ~14     !2, 1
         11        ASSIGN                                                   !3, ~14
   10    12        ASSIGN                                                   !4, <array>
   11    13      > FE_RESET_R                                       $17     !0, ->26
         14    > > FE_FETCH_R                                       ~18     $17, !5, ->26
         15    >   ASSIGN                                                   !6, ~18
   12    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !6
         19        DO_ICALL                                                 
   13    20        SUB                                              ~21     !3, !6
         21        SR                                               ~22     !1, ~21
         22      > JMPZ                                                     ~22, ->25
   14    23    >   ASSIGN_DIM                                               !4
         24        OP_DATA                                                  !5
   11    25    > > JMP                                                      ->14
         26    >   FE_FREE                                                  $17
   18    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.27 ms | 1396 KiB | 17 Q