3v4l.org

run code in 300+ PHP versions simultaneously
<?php function group($cond, $arr) { if (!$arr) return []; $e = array_shift($arr); $g = [$e]; while($cond($e, reset($arr))) { $g[] = array_shift($arr); } return array_merge([$g], group($cond, $arr)); } function it($m,$p){echo ($p?'OK':'NO')." It $m\n";} function eq($a,$b) {return $a==$b;} //echo it ('groups', group('eq', [1,5,5,6,6,6,7,9]) == [[1],[5,5],[6,6,6],[7],[9]]); it('spans elements which match', group(function ($x) { return $x < 3; }, [1, 2, 3]) === [[1, 2], [3]]); it('spans elements which match from the start', group(function ($x) { return $x == 3; }, [1, 6, 3, 3]) === [[], [1, 2, 3, 3]]); it('spans returns empty lists on empty list', group(function ($x) { return false; }, []) === [[], []]); it('groups elements recursively', array_group(function ($a, $b) { return $a === $b; }, [1, 1, 2, 1]) === [[1, 1], [2], [1]]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7fHRM
function name:  (null)
number of ops:  41
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'it'
          1        SEND_VAL                                                 'spans+elements+which+match'
          2        INIT_FCALL                                               'group'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7fHRM%3A24%240'
          4        SEND_VAL                                                 ~0
          5        SEND_VAL                                                 <array>
          6        DO_FCALL                                      0  $1      
          7        IS_IDENTICAL                                     ~2      $1, <array>
          8        SEND_VAL                                                 ~2
          9        DO_FCALL                                      0          
   25    10        INIT_FCALL                                               'it'
         11        SEND_VAL                                                 'spans+elements+which+match+from+the+start'
         12        INIT_FCALL                                               'group'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7fHRM%3A25%241'
         14        SEND_VAL                                                 ~4
         15        SEND_VAL                                                 <array>
         16        DO_FCALL                                      0  $5      
         17        IS_IDENTICAL                                     ~6      $5, <array>
         18        SEND_VAL                                                 ~6
         19        DO_FCALL                                      0          
   26    20        INIT_FCALL                                               'it'
         21        SEND_VAL                                                 'spans+returns+empty+lists+on+empty+list'
         22        INIT_FCALL                                               'group'
         23        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7fHRM%3A26%242'
         24        SEND_VAL                                                 ~8
         25        SEND_VAL                                                 <array>
         26        DO_FCALL                                      0  $9      
         27        IS_IDENTICAL                                     ~10     $9, <array>
         28        SEND_VAL                                                 ~10
         29        DO_FCALL                                      0          
   28    30        INIT_FCALL                                               'it'
         31        SEND_VAL                                                 'groups+elements+recursively'
         32        INIT_FCALL_BY_NAME                                       'array_group'
         33        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7fHRM%3A28%243'
         34        SEND_VAL_EX                                              ~12
         35        SEND_VAL_EX                                              <array>
         36        DO_FCALL                                      0  $13     
         37        IS_IDENTICAL                                     ~14     $13, <array>
         38        SEND_VAL                                                 ~14
         39        DO_FCALL                                      0          
         40      > RETURN                                                   1

Function 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 = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 12
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 12
Branch analysis from position: 25
Branch analysis from position: 12
filename:       /in/7fHRM
function name:  group
number of ops:  36
compiled vars:  !0 = $cond, !1 = $arr, !2 = $e, !3 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        BOOL_NOT                                         ~4      !1
          3      > JMPZ                                                     ~4, ->5
          4    > > RETURN                                                   <array>
    7     5    >   INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !2, $5
    8     9        INIT_ARRAY                                       ~7      !2
         10        ASSIGN                                                   !3, ~7
   10    11      > JMP                                                      ->17
   12    12    >   INIT_FCALL                                               'array_shift'
         13        SEND_REF                                                 !1
         14        DO_ICALL                                         $10     
         15        ASSIGN_DIM                                               !3
         16        OP_DATA                                                  $10
   10    17    >   INIT_DYNAMIC_CALL                                        !0
         18        SEND_VAR_EX                                              !2
         19        INIT_FCALL                                               'reset'
         20        SEND_REF                                                 !1
         21        DO_ICALL                                         $11     
         22        SEND_VAR_NO_REF_EX                                       $11
         23        DO_FCALL                                      0  $12     
         24      > JMPNZ                                                    $12, ->12
   15    25    >   INIT_FCALL                                               'array_merge'
         26        INIT_ARRAY                                       ~13     !3
         27        SEND_VAL                                                 ~13
         28        INIT_FCALL_BY_NAME                                       'group'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0  $14     
         32        SEND_VAR                                                 $14
         33        DO_ICALL                                         $15     
         34      > RETURN                                                   $15
   16    35*     > RETURN                                                   null

End of function 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/7fHRM
function name:  it
number of ops:  12
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     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/7fHRM
function name:  eq
number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     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%2F7fHRM%3A24%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7fHRM
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        IS_SMALLER                                       ~1      !0, 3
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7fHRM%3A24%240

Function %00%7Bclosure%7D%2Fin%2F7fHRM%3A25%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7fHRM
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        IS_EQUAL                                         ~1      !0, 3
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7fHRM%3A25%241

Function %00%7Bclosure%7D%2Fin%2F7fHRM%3A26%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7fHRM
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1      > RETURN                                                   <false>
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7fHRM%3A26%242

Function %00%7Bclosure%7D%2Fin%2F7fHRM%3A28%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7fHRM
function name:  {closure}
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_IDENTICAL                                     ~2      !0, !1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F7fHRM%3A28%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.37 ms | 1411 KiB | 26 Q