3v4l.org

run code in 300+ PHP versions simultaneously
<?php DEFINE('FILTER_OPTIONS', ['odd', 'even']); /* Array filtering * * @param $array array the input array * @param $filterParameter string 'odd' or 'even' * * @return array|bool it returns the filtered array. In any other case it should return false. */ function filterArray($array, $filterParameter) { if (! is_array($array) || ! in_array($filterParameter, FILTER_OPTIONS)) { return false; } return array_filter($array, function ($e) use ($filterParameter) { return $filterParameter === 'odd' ? $e % 2 === 1 : $e % 2 === 0; }); } $array = [1,2,3,4,5,6,7]; var_dump(filterArray(1, 'odd'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2UK6
function name:  (null)
number of ops:  13
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'FILTER_OPTIONS'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                                 
   21     4        ASSIGN                                                   !0, <array>
   22     5        INIT_FCALL                                               'var_dump'
          6        INIT_FCALL                                               'filterarray'
          7        SEND_VAL                                                 1
          8        SEND_VAL                                                 'odd'
          9        DO_FCALL                                      0  $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function filterarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Q2UK6
function name:  filterArray
number of ops:  22
compiled vars:  !0 = $array, !1 = $filterParameter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        TYPE_CHECK                                  128  ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPNZ_EX                                         ~3      ~3, ->12
          5    >   INIT_FCALL                                               'in_array'
          6        SEND_VAR                                                 !1
          7        FETCH_CONSTANT                                   ~4      'FILTER_OPTIONS'
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        BOOL_NOT                                         ~6      $5
         11        BOOL                                             ~3      ~6
         12    > > JMPZ                                                     ~3, ->14
   14    13    > > RETURN                                                   <false>
   16    14    >   INIT_FCALL                                               'array_filter'
         15        SEND_VAR                                                 !0
         16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQ2UK6%3A16%240'
         17        BIND_LEXICAL                                             ~7, !1
   18    18        SEND_VAL                                                 ~7
         19        DO_ICALL                                         $8      
         20      > RETURN                                                   $8
   19    21*     > RETURN                                                   null

End of function filterarray

Function %00%7Bclosure%7D%2Fin%2FQ2UK6%3A16%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2UK6
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $e, !1 = $filterParameter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   17     2        IS_IDENTICAL                                             !1, 'odd'
          3      > JMPZ                                                     ~2, ->8
          4    >   MOD                                              ~3      !0, 2
          5        IS_IDENTICAL                                     ~4      ~3, 1
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->11
          8    >   MOD                                              ~6      !0, 2
          9        IS_IDENTICAL                                     ~7      ~6, 0
         10        QM_ASSIGN                                        ~5      ~7
         11    > > RETURN                                                   ~5
   18    12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQ2UK6%3A16%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.23 ms | 1394 KiB | 22 Q