3v4l.org

run code in 300+ PHP versions simultaneously
<?php function any(array $array, callable $predicate) { return ((bool) count($array)) && array_reduce($array, function ($bool, $item) use ($predicate) { return $bool || (bool) $predicate($item); }, false); } function all(array $array, callable $predicate) { return ((bool) count($array)) && array_reduce($array, function ($bool, $item) use ($predicate) { return $bool && (bool) $predicate($item); }, true); } $valuesArray = [ [ false, false, true ], [ false, true, false ], [ false, true, true ], [ true, false, false ], [ true, false, true ], [ true, true, false ], [ true, true, true ], ]; foreach ($valuesArray as $values) { var_dump(['any' => any($values, function ($value) { return $value; })]); var_dump(['all' => all($values, function ($value) { return $value; })]); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 22
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/R3j0Q
function name:  (null)
number of ops:  24
compiled vars:  !0 = $valuesArray, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   25     1      > FE_RESET_R                                       $3      !0, ->22
          2    > > FE_FETCH_R                                               $3, !1, ->22
   27     3    >   INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'any'
          5        SEND_VAR                                                 !1
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR3j0Q%3A27%242'
   29     7        SEND_VAL                                                 ~4
          8        DO_FCALL                                      0  $5      
          9        INIT_ARRAY                                       ~6      $5, 'any'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                                 
   31    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'all'
         14        SEND_VAR                                                 !1
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR3j0Q%3A31%243'
   33    16        SEND_VAL                                                 ~8
         17        DO_FCALL                                      0  $9      
         18        INIT_ARRAY                                       ~10     $9, 'all'
         19        SEND_VAL                                                 ~10
         20        DO_ICALL                                                 
   25    21      > JMP                                                      ->2
         22    >   FE_FREE                                                  $3
   35    23      > RETURN                                                   1

Function any:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/R3j0Q
function name:  any
number of ops:  15
compiled vars:  !0 = $array, !1 = $predicate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        COUNT                                            ~2      !0
          3        BOOL                                             ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->13
          5    >   INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR3j0Q%3A4%240'
          8        BIND_LEXICAL                                             ~4, !1
    6     9        SEND_VAL                                                 ~4
         10        SEND_VAL                                                 <false>
         11        DO_ICALL                                         $5      
         12        BOOL                                             ~3      $5
         13    > > RETURN                                                   ~3
    7    14*     > RETURN                                                   null

End of function any

Function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A4%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/R3j0Q
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $bool, !1 = $item, !2 = $predicate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
    5     3      > JMPNZ_EX                                         ~3      !0, ->9
          4    >   INIT_DYNAMIC_CALL                                        !2
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $4      
          7        BOOL                                             ~5      $4
          8        BOOL                                             ~3      ~5
          9    > > RETURN                                                   ~3
    6    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A4%240

Function all:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/R3j0Q
function name:  all
number of ops:  15
compiled vars:  !0 = $array, !1 = $predicate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        COUNT                                            ~2      !0
          3        BOOL                                             ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->13
          5    >   INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR3j0Q%3A10%241'
          8        BIND_LEXICAL                                             ~4, !1
   12     9        SEND_VAL                                                 ~4
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $5      
         12        BOOL                                             ~3      $5
         13    > > RETURN                                                   ~3
   13    14*     > RETURN                                                   null

End of function all

Function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A10%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/R3j0Q
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $bool, !1 = $item, !2 = $predicate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   11     3      > JMPZ_EX                                          ~3      !0, ->9
          4    >   INIT_DYNAMIC_CALL                                        !2
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $4      
          7        BOOL                                             ~5      $4
          8        BOOL                                             ~3      ~5
          9    > > RETURN                                                   ~3
   12    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A10%241

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

End of function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A27%242

Function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A31%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R3j0Q
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1      > RETURN                                                   !0
   33     2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FR3j0Q%3A31%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.57 ms | 1407 KiB | 19 Q