3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* span :: (a -> Bool) -> [a] -> ([a],[a]) span _ xs@[] = (xs, xs) span p xs@(x:xs') | p x = let (ys,zs) = span p xs' in (x:ys,zs) | otherwise = ([],xs) */ function span($p, $xs) { if (empty($xs)) { return [[], []]; } $xs_ = $xs; $x = array_shift($xs_); if ($p($x)) { list($ys, $zs) = span($p, $xs_); return [array_merge([$x], $ys), $zs]; } return [[], $xs]; } /* groupBy :: (a -> a -> Bool) -> [a] -> [[a]] groupBy _ [] = [] groupBy eq (x:xs) = (x:ys) : groupBy eq zs where (ys,zs) = span (eq x) xs */ function array_group(callable $eq, array $xs) { if (empty($xs)) { return []; } $x = array_shift($xs); // curry of $eq $eqx = function ($y) use ($eq, $x) { return $eq($x, $y); }; list($ys, $zs) = span($eqx, $xs); return array_merge([array_merge([$x], $ys)], array_group($eq, $zs)); } function it($m,$p){echo ($p?'OK':'NO')." It $m\n"; if(!$p){$GLOBALS['f']=1;}} print_r(array_group(function ($a, $b) { return ($a == ($b-1)) || ($a==$b); }, [1, 1, 2, 3, 1]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/suXCq
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'array_group'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FsuXCq%3A49%241'
          3        SEND_VAL                                                 ~0
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0  $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function span:
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
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 31
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/suXCq
function name:  span
number of ops:  35
compiled vars:  !0 = $p, !1 = $xs, !2 = $xs_, !3 = $x, !4 = $ys, !5 = $zs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~6, ->5
   12     4    > > RETURN                                                   <array>
   15     5    >   ASSIGN                                                   !2, !1
   16     6        INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !2
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
   18    10        INIT_DYNAMIC_CALL                                        !0
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $10     
         13      > JMPZ                                                     $10, ->31
   19    14    >   INIT_FCALL_BY_NAME                                       'span'
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $11     
         18        FETCH_LIST_R                                     $12     $11, 0
         19        ASSIGN                                                   !4, $12
         20        FETCH_LIST_R                                     $14     $11, 1
         21        ASSIGN                                                   !5, $14
         22        FREE                                                     $11
   21    23        INIT_FCALL                                               'array_merge'
         24        INIT_ARRAY                                       ~16     !3
         25        SEND_VAL                                                 ~16
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $17     
         28        INIT_ARRAY                                       ~18     $17
         29        ADD_ARRAY_ELEMENT                                ~18     !5
         30      > RETURN                                                   ~18
   24    31    >   INIT_ARRAY                                       ~19     <array>
         32        ADD_ARRAY_ELEMENT                                ~19     !1
         33      > RETURN                                                   ~19
   25    34*     > RETURN                                                   null

End of function span

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/suXCq
function name:  array_group
number of ops:  38
compiled vars:  !0 = $eq, !1 = $xs, !2 = $x, !3 = $eqx, !4 = $ys, !5 = $zs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~6, ->5
   35     4    > > RETURN                                                   <array>
   38     5    >   INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !2, $7
   40     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FsuXCq%3A40%240'
         10        BIND_LEXICAL                                             ~9, !0
         11        BIND_LEXICAL                                             ~9, !2
         12        ASSIGN                                                   !3, ~9
   42    13        INIT_FCALL                                               'span'
         14        SEND_VAR                                                 !3
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $11     
         17        FETCH_LIST_R                                     $12     $11, 0
         18        ASSIGN                                                   !4, $12
         19        FETCH_LIST_R                                     $14     $11, 1
         20        ASSIGN                                                   !5, $14
         21        FREE                                                     $11
   44    22        INIT_FCALL                                               'array_merge'
         23        INIT_FCALL                                               'array_merge'
         24        INIT_ARRAY                                       ~16     !2
         25        SEND_VAL                                                 ~16
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $17     
         28        INIT_ARRAY                                       ~18     $17
         29        SEND_VAL                                                 ~18
         30        INIT_FCALL_BY_NAME                                       'array_group'
         31        SEND_VAR_EX                                              !0
         32        SEND_VAR_EX                                              !5
         33        DO_FCALL                                      0  $19     
         34        SEND_VAR                                                 $19
         35        DO_ICALL                                         $20     
         36      > RETURN                                                   $20
   45    37*     > RETURN                                                   null

End of function array_group

Function %00%7Bclosure%7D%2Fin%2FsuXCq%3A40%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/suXCq
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $y, !1 = $eq, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_VAR_EX                                              !2
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FsuXCq%3A40%240

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
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
Branch analysis from position: 16
filename:       /in/suXCq
function name:  it
number of ops:  17
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     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        BOOL_NOT                                         ~7      !1
         12      > JMPZ                                                     ~7, ->16
         13    >   FETCH_W                      global              $8      'GLOBALS'
         14        ASSIGN_DIM                                               $8, 'f'
         15        OP_DATA                                                  1
         16    > > RETURN                                                   null

End of function it

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.41 ms | 1411 KiB | 21 Q