3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_group(array $arr1, callable $compare): array { $groups = []; $group = []; $prev = NULL; foreach ($arr1 as $value) { if ($group && !$compare($prev, $value)) { $groups[] = $group; $group = []; } $group[] = $value; $prev = $value; } if ($group) { $groups[] = $group; } return $groups; } $arr1 = array(1,2,2,3,1,2,0,4,5,2); $compare = fn ($a, $b) => $a <= $b; print_r(array_group($arr1, $compare));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KsL3o
function name:  (null)
number of ops:  11
compiled vars:  !0 = $arr1, !1 = $compare
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                       !0, <array>
   23     1        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          2        ASSIGN                                                       !1, ~3
   24     3        INIT_FCALL                                                   'print_r'
          4        INIT_FCALL                                                   'array_group'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        DO_FCALL                                          0  $5      
          8        SEND_VAR                                                     $5
          9        DO_ICALL                                                     
         10      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KsL3o
function name:  {closure:/in/KsL3o:23}
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        IS_SMALLER_OR_EQUAL                                  ~2      !0, !1
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 0

Function array_group:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 18
Branch analysis from position: 14
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 22
filename:       /in/KsL3o
function name:  array_group
number of ops:  30
compiled vars:  !0 = $arr1, !1 = $compare, !2 = $groups, !3 = $group, !4 = $prev, !5 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        ASSIGN                                                       !2, <array>
    6     3        ASSIGN                                                       !3, <array>
    7     4        ASSIGN                                                       !4, null
    8     5      > FE_RESET_R                                           $9      !0, ->22
          6    > > FE_FETCH_R                                                   $9, !5, ->22
    9     7    > > JMPZ_EX                                              ~10     !3, ->14
          8    >   INIT_DYNAMIC_CALL                                            !1
          9        SEND_VAR_EX                                                  !4
         10        SEND_VAR_EX                                                  !5
         11        DO_FCALL                                          0  $11     
         12        BOOL_NOT                                             ~12     $11
         13        BOOL                                                 ~10     ~12
         14    > > JMPZ                                                         ~10, ->18
   10    15    >   ASSIGN_DIM                                                   !2
         16        OP_DATA                                                      !3
   11    17        ASSIGN                                                       !3, <array>
   13    18    >   ASSIGN_DIM                                                   !3
         19        OP_DATA                                                      !5
   14    20        ASSIGN                                                       !4, !5
    8    21      > JMP                                                          ->6
         22    >   FE_FREE                                                      $9
   16    23      > JMPZ                                                         !3, ->26
   17    24    >   ASSIGN_DIM                                                   !2
         25        OP_DATA                                                      !3
   19    26    >   VERIFY_RETURN_TYPE                                           !2
         27      > RETURN                                                       !2
   20    28*       VERIFY_RETURN_TYPE                                           
         29*     > RETURN                                                       null

End of function array_group

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.4 ms | 1777 KiB | 15 Q