3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_group($cond, &$arr, $e = null) { if (! empty($arr) && ($e === null || $cond($e, reset($arr)))) { $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($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/mWsj5
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%2FmWsj5%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%2FmWsj5%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 = 46) Position 1 = 6, Position 2 = 17
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 = 18, Position 2 = 33
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 17
filename:       /in/mWsj5
function name:  find_group
number of ops:  35
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        ISSET_ISEMPTY_CV                                 ~3      !1
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ_EX                                          ~4      ~4, ->17
          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    >   BOOL                                             ~4      ~5
         17    > > JMPZ                                                     ~4, ->33
    7    18    >   INIT_FCALL                                               'array_shift'
         19        SEND_REF                                                 !1
         20        DO_ICALL                                         $8      
         21        ASSIGN                                                   !2, $8
    8    22        INIT_FCALL                                               'array_merge'
         23        INIT_ARRAY                                       ~10     !2
         24        SEND_VAL                                                 ~10
         25        INIT_FCALL_BY_NAME                                       'find_group'
         26        SEND_VAR_EX                                              !0
         27        SEND_VAR_EX                                              !1
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0  $11     
         30        SEND_VAR                                                 $11
         31        DO_ICALL                                         $12     
         32      > RETURN                                                   $12
   11    33    > > RETURN                                                   <array>
   12    34*     > 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/mWsj5
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                                                 !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
   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/mWsj5
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/mWsj5
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%2FmWsj5%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/mWsj5
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%2FmWsj5%3A31%240

Function %00%7Bclosure%7D%2Fin%2FmWsj5%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/mWsj5
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%2FmWsj5%3A32%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
190.91 ms | 1415 KiB | 26 Q