3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_group($cond, &$arr, $e = null) { if (empty($arr)) return []; if ($e === null || $cond($e, reset($arr))) { $ne = array_shift($arr); return array_merge([$ne], find_group($cond, $arr, ($e === null) ? $ne : $e)); } return []; } function array_group($cond, $arr) { if (empty($arr)) return []; /*while($cond($e, reset($arr))) { $g[] = array_shift($arr); }*/ return array_merge([find_group($cond, $arr)], array_group($cond, $arr)); } function it($m,$p){echo ($p?'OK':'NO')." It $m\n";} function eq($a,$b) {return $a==$b;} echo it ('groups', array_group('eq', [1,5,5,6,6,6,7,9]) == [[1],[5,5],[6,6,6],[7],[9]]); echo it ('groups by comparing with first item of each group', array_group(function ($a, $b) { return ($a == ($b-1)) || ($a==$b); }, [1,1,2,3,1]) == [[1,1,2],[3],[1]]); echo it ('groups by comparing with first item of each group', array_group(function ($a, $b) { return ($a == ($b-1)) || ($a==$b); }, [1,1,2,1,3,1]) == [[1,1,2,1],[3],[1]]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TVBGF
function name:  (null)
number of ops:  33
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'it'
          1        SEND_VAL                                                 'groups'
          2        INIT_FCALL                                               'array_group'
          3        SEND_VAL                                                 'eq'
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0  $0      
          6        IS_EQUAL                                         ~1      $0, <array>
          7        SEND_VAL                                                 ~1
          8        DO_FCALL                                      0  $2      
          9        ECHO                                                     $2
   33    10        INIT_FCALL                                               'it'
         11        SEND_VAL                                                 'groups+by+comparing+with+first+item+of+each+group'
         12        INIT_FCALL                                               'array_group'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTVBGF%3A33%240'
         14        SEND_VAL                                                 ~3
         15        SEND_VAL                                                 <array>
         16        DO_FCALL                                      0  $4      
         17        IS_EQUAL                                         ~5      $4, <array>
         18        SEND_VAL                                                 ~5
         19        DO_FCALL                                      0  $6      
         20        ECHO                                                     $6
   34    21        INIT_FCALL                                               'it'
         22        SEND_VAL                                                 'groups+by+comparing+with+first+item+of+each+group'
         23        INIT_FCALL                                               'array_group'
         24        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTVBGF%3A34%241'
         25        SEND_VAL                                                 ~7
         26        SEND_VAL                                                 <array>
         27        DO_FCALL                                      0  $8      
         28        IS_EQUAL                                         ~9      $8, <array>
         29        SEND_VAL                                                 ~9
         30        DO_FCALL                                      0  $10     
         31        ECHO                                                     $10
         32      > RETURN                                                   1

Function find_group:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 37
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/TVBGF
function name:  find_group
number of ops:  39
compiled vars:  !0 = $cond, !1 = $arr, !2 = $e, !3 = $ne
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    5     3        ISSET_ISEMPTY_CV                                         !1
          4      > JMPZ                                                     ~4, ->6
          5    > > RETURN                                                   <array>
    7     6    >   TYPE_CHECK                                    2  ~5      !2
          7      > JMPNZ_EX                                         ~5      ~5, ->16
          8    >   INIT_DYNAMIC_CALL                                        !0
          9        SEND_VAR_EX                                              !2
         10        INIT_FCALL                                               'reset'
         11        SEND_REF                                                 !1
         12        DO_ICALL                                         $6      
         13        SEND_VAR_NO_REF_EX                                       $6
         14        DO_FCALL                                      0  $7      
         15        BOOL                                             ~5      $7
         16    > > JMPZ                                                     ~5, ->37
    9    17    >   INIT_FCALL                                               'array_shift'
         18        SEND_REF                                                 !1
         19        DO_ICALL                                         $8      
         20        ASSIGN                                                   !3, $8
   10    21        INIT_FCALL                                               'array_merge'
         22        INIT_ARRAY                                       ~10     !3
         23        SEND_VAL                                                 ~10
         24        INIT_FCALL_BY_NAME                                       'find_group'
         25        SEND_VAR_EX                                              !0
         26        SEND_VAR_EX                                              !1
         27        TYPE_CHECK                                    2          !2
         28      > JMPZ                                                     ~11, ->31
         29    >   QM_ASSIGN                                        ~12     !3
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~12     !2
         32    >   SEND_VAL_EX                                              ~12
         33        DO_FCALL                                      0  $13     
         34        SEND_VAR                                                 $13
         35        DO_ICALL                                         $14     
         36      > RETURN                                                   $14
   13    37    > > RETURN                                                   <array>
   14    38*     > RETURN                                                   null

End of function find_group

Function array_group:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TVBGF
function name:  array_group
number of ops:  20
compiled vars:  !0 = $cond, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~2, ->5
          4    > > RETURN                                                   <array>
   25     5    >   INIT_FCALL                                               'array_merge'
          6        INIT_FCALL                                               'find_group'
          7        SEND_VAR                                                 !0
          8        SEND_REF                                                 !1
          9        DO_FCALL                                      0  $3      
         10        INIT_ARRAY                                       ~4      $3
         11        SEND_VAL                                                 ~4
         12        INIT_FCALL_BY_NAME                                       'array_group'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $5      
         16        SEND_VAR                                                 $5
         17        DO_ICALL                                         $6      
         18      > RETURN                                                   $6
   26    19*     > RETURN                                                   null

End of function array_group

Function it:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TVBGF
function name:  it
number of ops:  12
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > JMPZ                                                     !1, ->5
          3    >   QM_ASSIGN                                        ~2      'OK'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      'NO'
          6    >   ROPE_INIT                                     3  ~4      '+It+'
          7        ROPE_ADD                                      1  ~4      ~4, !0
          8        ROPE_END                                      2  ~3      ~4, '%0A'
          9        CONCAT                                           ~6      ~2, ~3
         10        ECHO                                                     ~6
         11      > RETURN                                                   null

End of function it

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

End of function eq

Function %00%7Bclosure%7D%2Fin%2FTVBGF%3A33%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/TVBGF
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        SUB                                              ~2      !1, 1
          3        IS_EQUAL                                         ~3      !0, ~2
          4      > JMPNZ_EX                                         ~3      ~3, ->7
          5    >   IS_EQUAL                                         ~4      !0, !1
          6        BOOL                                             ~3      ~4
          7    > > RETURN                                                   ~3
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTVBGF%3A33%240

Function %00%7Bclosure%7D%2Fin%2FTVBGF%3A34%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/TVBGF
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        SUB                                              ~2      !1, 1
          3        IS_EQUAL                                         ~3      !0, ~2
          4      > JMPNZ_EX                                         ~3      ~3, ->7
          5    >   IS_EQUAL                                         ~4      !0, !1
          6        BOOL                                             ~3      ~4
          7    > > RETURN                                                   ~3
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTVBGF%3A34%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.69 ms | 1411 KiB | 26 Q