3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Etc; /** * Determines whether any element of `$array` satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return boolean `TRUE` if any element satisfies `$predicate`, `FALSE` otherwise */ function array_any(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return true; } } return false; } /** * Determines whether all elements of `$array` satisfy `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return boolean `TRUE` if all elements satisfy `$predicate`, `FALSE` otherwise */ function array_all(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { continue; } return false; } return true; } /** * Returns the first element value of `$array` that satisfies `$predicate` * * @param array $array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @param mixed $default [optional] The value to return if no elements satisfy `$predicate` * @return mixed The element value, `$default` otherwise */ function array_first(array $array, callable $predicate = null, $default = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return $value; } } return $default; } /** * Returns the first element key of `$array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return mixed The element key, `NULL` otherwise */ function array_first_key(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return $key; } } return null; } /** * Returns the last element value of `$array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @param mixed $default [optional] The value to return if no elements satisfy `$predicate` * @return mixed The element value, `$default` otherwise */ function array_last(array $array, callable $predicate = null, $default = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach (array_reverse(array_keys($array)) as $key) { $value = $array[$key]; if ((boolean) $predicate($value, $key)) { return $value; } } return $default; } /** * Returns the last element key of $array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return mixed The element key, `NULL` otherwise */ function array_last_key(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach (array_reverse(array_keys($array)) as $key) { $value = $array[$key]; if ((boolean) $predicate($value, $key)) { return $key; } } return null; } var_dump(array_last_key([null, null, 'a', null]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  142     0  E >   INIT_NS_FCALL_BY_NAME                                    'Etc%5Cvar_dump'
          1        INIT_NS_FCALL_BY_NAME                                    'Etc%5Carray_last_key'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR_NO_REF_EX                                       $0
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function etc%5Carray_any:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/2hlkI
function name:  Etc\array_any
number of ops:  21
compiled vars:  !0 = $array, !1 = $predicate, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   14     2        JMP_SET                                          ~4      !1, ->5
          3        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A14%240'
   16     4        QM_ASSIGN                                        ~4      ~5
   14     5        ASSIGN                                                   !1, ~4
   17     6      > FE_RESET_R                                       $7      !0, ->18
          7    > > FE_FETCH_R                                       ~8      $7, !2, ->18
          8    >   ASSIGN                                                   !3, ~8
   19     9        INIT_DYNAMIC_CALL                                        !1
         10        SEND_VAR_EX                                              !2
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $10     
         13        BOOL                                             ~11     $10
         14      > JMPZ                                                     ~11, ->17
   21    15    >   FE_FREE                                                  $7
         16      > RETURN                                                   <true>
   17    17    > > JMP                                                      ->7
         18    >   FE_FREE                                                  $7
   24    19      > RETURN                                                   <false>
   25    20*     > RETURN                                                   null

End of function etc%5Carray_any

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   16     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A14%240

Function etc%5Carray_all:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/2hlkI
function name:  Etc\array_all
number of ops:  22
compiled vars:  !0 = $array, !1 = $predicate, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   36     2        JMP_SET                                          ~4      !1, ->5
          3        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A36%241'
   38     4        QM_ASSIGN                                        ~4      ~5
   36     5        ASSIGN                                                   !1, ~4
   39     6      > FE_RESET_R                                       $7      !0, ->19
          7    > > FE_FETCH_R                                       ~8      $7, !2, ->19
          8    >   ASSIGN                                                   !3, ~8
   41     9        INIT_DYNAMIC_CALL                                        !1
         10        SEND_VAR_EX                                              !2
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $10     
         13        BOOL                                             ~11     $10
         14      > JMPZ                                                     ~11, ->16
   43    15    > > JMP                                                      ->7
   45    16    >   FE_FREE                                                  $7
         17      > RETURN                                                   <false>
   39    18*       JMP                                                      ->7
         19    >   FE_FREE                                                  $7
   47    20      > RETURN                                                   <true>
   48    21*     > RETURN                                                   null

End of function etc%5Carray_all

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A36%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   38     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A36%241

Function etc%5Carray_first:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/2hlkI
function name:  Etc\array_first
number of ops:  22
compiled vars:  !0 = $array, !1 = $predicate, !2 = $default, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   60     3        JMP_SET                                          ~5      !1, ->6
          4        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A60%242'
   62     5        QM_ASSIGN                                        ~5      ~6
   60     6        ASSIGN                                                   !1, ~5
   63     7      > FE_RESET_R                                       $8      !0, ->19
          8    > > FE_FETCH_R                                       ~9      $8, !3, ->19
          9    >   ASSIGN                                                   !4, ~9
   65    10        INIT_DYNAMIC_CALL                                        !1
         11        SEND_VAR_EX                                              !3
         12        SEND_VAR_EX                                              !4
         13        DO_FCALL                                      0  $11     
         14        BOOL                                             ~12     $11
         15      > JMPZ                                                     ~12, ->18
   67    16    >   FE_FREE                                                  $8
         17      > RETURN                                                   !3
   63    18    > > JMP                                                      ->8
         19    >   FE_FREE                                                  $8
   70    20      > RETURN                                                   !2
   71    21*     > RETURN                                                   null

End of function etc%5Carray_first

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A60%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   61     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   62     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A60%242

Function etc%5Carray_first_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/2hlkI
function name:  Etc\array_first_key
number of ops:  21
compiled vars:  !0 = $array, !1 = $predicate, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   82     2        JMP_SET                                          ~4      !1, ->5
          3        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A82%243'
   84     4        QM_ASSIGN                                        ~4      ~5
   82     5        ASSIGN                                                   !1, ~4
   85     6      > FE_RESET_R                                       $7      !0, ->18
          7    > > FE_FETCH_R                                       ~8      $7, !2, ->18
          8    >   ASSIGN                                                   !3, ~8
   87     9        INIT_DYNAMIC_CALL                                        !1
         10        SEND_VAR_EX                                              !2
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $10     
         13        BOOL                                             ~11     $10
         14      > JMPZ                                                     ~11, ->17
   89    15    >   FE_FREE                                                  $7
         16      > RETURN                                                   !3
   85    17    > > JMP                                                      ->7
         18    >   FE_FREE                                                  $7
   92    19      > RETURN                                                   null
   93    20*     > RETURN                                                   null

End of function etc%5Carray_first_key

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A82%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   83     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   84     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A82%243

Function etc%5Carray_last:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/2hlkI
function name:  Etc\array_last
number of ops:  29
compiled vars:  !0 = $array, !1 = $predicate, !2 = $default, !3 = $key, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
  105     3        JMP_SET                                          ~5      !1, ->6
          4        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A105%244'
  107     5        QM_ASSIGN                                        ~5      ~6
  105     6        ASSIGN                                                   !1, ~5
  108     7        INIT_NS_FCALL_BY_NAME                                    'Etc%5Carray_reverse'
          8        INIT_NS_FCALL_BY_NAME                                    'Etc%5Carray_keys'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR_NO_REF_EX                                       $8
         12        DO_FCALL                                      0  $9      
         13      > FE_RESET_R                                       $10     $9, ->26
         14    > > FE_FETCH_R                                               $10, !3, ->26
  110    15    >   FETCH_DIM_R                                      ~11     !0, !3
         16        ASSIGN                                                   !4, ~11
  111    17        INIT_DYNAMIC_CALL                                        !1
         18        SEND_VAR_EX                                              !4
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $13     
         21        BOOL                                             ~14     $13
         22      > JMPZ                                                     ~14, ->25
  113    23    >   FE_FREE                                                  $10
         24      > RETURN                                                   !4
  108    25    > > JMP                                                      ->14
         26    >   FE_FREE                                                  $10
  116    27      > RETURN                                                   !2
  117    28*     > RETURN                                                   null

End of function etc%5Carray_last

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A105%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  105     0  E >   RECV                                             !0      
  106     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
  107     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A105%244

Function etc%5Carray_last_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 25
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/2hlkI
function name:  Etc\array_last_key
number of ops:  28
compiled vars:  !0 = $array, !1 = $predicate, !2 = $key, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
  128     2        JMP_SET                                          ~4      !1, ->5
          3        DECLARE_LAMBDA_FUNCTION                                  '%00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A128%245'
  130     4        QM_ASSIGN                                        ~4      ~5
  128     5        ASSIGN                                                   !1, ~4
  131     6        INIT_NS_FCALL_BY_NAME                                    'Etc%5Carray_reverse'
          7        INIT_NS_FCALL_BY_NAME                                    'Etc%5Carray_keys'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR_NO_REF_EX                                       $7
         11        DO_FCALL                                      0  $8      
         12      > FE_RESET_R                                       $9      $8, ->25
         13    > > FE_FETCH_R                                               $9, !2, ->25
  133    14    >   FETCH_DIM_R                                      ~10     !0, !2
         15        ASSIGN                                                   !3, ~10
  134    16        INIT_DYNAMIC_CALL                                        !1
         17        SEND_VAR_EX                                              !3
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0  $12     
         20        BOOL                                             ~13     $12
         21      > JMPZ                                                     ~13, ->24
  136    22    >   FE_FREE                                                  $9
         23      > RETURN                                                   !2
  131    24    > > JMP                                                      ->13
         25    >   FE_FREE                                                  $9
  139    26      > RETURN                                                   null
  140    27*     > RETURN                                                   null

End of function etc%5Carray_last_key

Function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A128%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2hlkI
function name:  Etc\{closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     0  E >   RECV                                             !0      
  129     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
  130     4*     > RETURN                                                   null

End of function %00etc%5C%7Bclosure%7D%2Fin%2F2hlkI%3A128%245

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.21 ms | 1419 KiB | 20 Q