3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_group($cond, &$arr, $e = null) { if ($cond($e, reset($arr) || $e === null)) { $e = array_shift($arr); return array_merge([$e], find_group($cond, $arr, $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($arr, $cond)], 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/sTUsn
function name:  (null)
number of ops:  33
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     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
   31    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%2FsTUsn%3A31%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
   32    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%2FsTUsn%3A32%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 = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/sTUsn
function name:  find_group
number of ops:  31
compiled vars:  !0 = $cond, !1 = $arr, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    5     3        INIT_DYNAMIC_CALL                                        !0
          4        SEND_VAR_EX                                              !2
          5        INIT_FCALL                                               'reset'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $3      
          8      > JMPNZ_EX                                         ~4      $3, ->11
          9    >   TYPE_CHECK                                    2  ~5      !2
         10        BOOL                                             ~4      ~5
         11    >   SEND_VAL_EX                                              ~4
         12        DO_FCALL                                      0  $6      
         13      > JMPZ                                                     $6, ->29
    7    14    >   INIT_FCALL                                               'array_shift'
         15        SEND_REF                                                 !1
         16        DO_ICALL                                         $7      
         17        ASSIGN                                                   !2, $7
    8    18        INIT_FCALL                                               'array_merge'
         19        INIT_ARRAY                                       ~9      !2
         20        SEND_VAL                                                 ~9
         21        INIT_FCALL_BY_NAME                                       'find_group'
         22        SEND_VAR_EX                                              !0
         23        SEND_VAR_EX                                              !1
         24        SEND_VAR_EX                                              !2
         25        DO_FCALL                                      0  $10     
         26        SEND_VAR                                                 $10
         27        DO_ICALL                                         $11     
         28      > RETURN                                                   $11
   11    29    > > RETURN                                                   <array>
   12    30*     > 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/sTUsn
function name:  array_group
number of ops:  20
compiled vars:  !0 = $cond, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~2, ->5
          4    > > RETURN                                                   <array>
   23     5    >   INIT_FCALL                                               'array_merge'
          6        INIT_FCALL                                               'find_group'
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !0
          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
   24    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/sTUsn
function name:  it
number of ops:  12
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     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/sTUsn
function name:  eq
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     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%2FsTUsn%3A31%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/sTUsn
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     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%2FsTUsn%3A31%240

Function %00%7Bclosure%7D%2Fin%2FsTUsn%3A32%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/sTUsn
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     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%2FsTUsn%3A32%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.48 ms | 1411 KiB | 26 Q