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($x); if ($p($x)) { list($ys, $zs) = span($p, $xs_); return [array_unshift($ys, $x), $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); list($ys, $zs) = span($eq($x), $xs); } function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);} it('spans elements', span(function ($x) { return $x < 2; }, [1, 2, 3]) === [[1, 2], [3]]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYHOR
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   INIT_FCALL                                               'it'
          1        SEND_VAL                                                 'spans+elements'
          2        INIT_FCALL                                               'span'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FXYHOR%3A45%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          
         10      > 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 = 30
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYHOR
function name:  span
number of ops:  34
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                                                 !3
          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, ->30
   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_unshift'
         24        SEND_REF                                                 !4
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $16     
         27        INIT_ARRAY                                       ~17     $16
         28        ADD_ARRAY_ELEMENT                                ~17     !5
         29      > RETURN                                                   ~17
   24    30    >   INIT_ARRAY                                       ~18     <array>
         31        ADD_ARRAY_ELEMENT                                ~18     !1
         32      > RETURN                                                   ~18
   25    33*     > 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/XYHOR
function name:  array_group
number of ops:  22
compiled vars:  !0 = $eq, !1 = $xs, !2 = $x, !3 = $ys, !4 = $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                                                     ~5, ->5
   35     4    > > RETURN                                                   <array>
   38     5    >   INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !2, $6
   40     9        INIT_FCALL                                               'span'
         10        INIT_DYNAMIC_CALL                                        !0
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0  $9      
         16        FETCH_LIST_R                                     $10     $9, 0
         17        ASSIGN                                                   !3, $10
         18        FETCH_LIST_R                                     $12     $9, 1
         19        ASSIGN                                                   !4, $12
         20        FREE                                                     $9
   41    21      > 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
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/XYHOR
function name:  it
number of ops:  17
compiled vars:  !0 = $m, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > JMPZ                                                     !1, ->5
          3    >   QM_ASSIGN                                        ~2      '%E2%9C%94%EF%B8%8E'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      '%E2%9C%98'
          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 done:
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 = 79) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYHOR
function name:  done
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   BEGIN_SILENCE                                    ~0      
          1        FETCH_R                      global              ~1      'GLOBALS'
          2        FETCH_DIM_R                                      ~2      ~1, 'f'
          3        END_SILENCE                                              ~0
          4      > JMPZ                                                     ~2, ->6
          5    > > EXIT                                                     1
          6    > > RETURN                                                   null

End of function done

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

End of function %00%7Bclosure%7D%2Fin%2FXYHOR%3A45%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.93 ms | 1398 KiB | 20 Q