3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param array $numbers * * @return array */ function find_even(array $numbers) { if (count($numbers) === 0) { return []; } if (count($numbers) === 1) { return has_even($numbers) ? $numbers : []; } list($left, $right) = array_chunk($numbers, ceil(count($numbers) / 2)); $left = has_even($left) ? $left : []; $right = has_even($right) ? $right : []; $leftResult = (count($left) > 1) ? find_even($left) : $left; $rightResult = (count($right) > 1) ? find_even($right) : $right; return array_merge($leftResult, $rightResult); } /** * @param array $numbers * * @return bool */ function has_even(array $numbers) { echo join(' ', $numbers) . PHP_EOL; foreach ($numbers as $number) { if ($number % 2 === 0) { return true; } } return false; } $numbers = [1, 2, 3, 7, 5, 7, 1, 3, 4, 9, 7, 3, 5, 7, 9]; echo join(' ', $numbers) . PHP_EOL . PHP_EOL; echo PHP_EOL . join(' ', find_even($numbers)) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EQtXT
function name:  (null)
number of ops:  19
compiled vars:  !0 = $numbers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, <array>
   45     1        INIT_FCALL                                               'join'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        CONCAT                                           ~4      ~3, '%0A'
          7        ECHO                                                     ~4
   47     8        INIT_FCALL                                               'join'
          9        SEND_VAL                                                 '+'
         10        INIT_FCALL                                               'find_even'
         11        SEND_VAR                                                 !0
         12        DO_FCALL                                      0  $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                         $6      
         15        CONCAT                                           ~7      '%0A', $6
         16        CONCAT                                           ~8      ~7, '%0A'
         17        ECHO                                                     ~8
         18      > RETURN                                                   1

Function find_even:
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 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
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: 16
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
Branch analysis from position: 64
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
Branch analysis from position: 54
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
Branch analysis from position: 44
filename:       /in/EQtXT
function name:  find_even
number of ops:  72
compiled vars:  !0 = $numbers, !1 = $left, !2 = $right, !3 = $leftResult, !4 = $rightResult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        COUNT                                            ~5      !0
          2        IS_IDENTICAL                                             ~5, 0
          3      > JMPZ                                                     ~6, ->5
   10     4    > > RETURN                                                   <array>
   13     5    >   COUNT                                            ~7      !0
          6        IS_IDENTICAL                                             ~7, 1
          7      > JMPZ                                                     ~8, ->16
   14     8    >   INIT_FCALL_BY_NAME                                       'has_even'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $9      
         11      > JMPZ                                                     $9, ->14
         12    >   QM_ASSIGN                                        ~10     !0
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~10     <array>
         15    > > RETURN                                                   ~10
   17    16    >   INIT_FCALL                                               'array_chunk'
         17        SEND_VAR                                                 !0
         18        INIT_FCALL                                               'ceil'
         19        COUNT                                            ~11     !0
         20        DIV                                              ~12     ~11, 2
         21        SEND_VAL                                                 ~12
         22        DO_ICALL                                         $13     
         23        SEND_VAR                                                 $13
         24        DO_ICALL                                         $14     
         25        FETCH_LIST_R                                     $15     $14, 0
         26        ASSIGN                                                   !1, $15
         27        FETCH_LIST_R                                     $17     $14, 1
         28        ASSIGN                                                   !2, $17
         29        FREE                                                     $14
   19    30        INIT_FCALL_BY_NAME                                       'has_even'
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0  $19     
         33      > JMPZ                                                     $19, ->36
         34    >   QM_ASSIGN                                        ~20     !1
         35      > JMP                                                      ->37
         36    >   QM_ASSIGN                                        ~20     <array>
         37    >   ASSIGN                                                   !1, ~20
   20    38        INIT_FCALL_BY_NAME                                       'has_even'
         39        SEND_VAR_EX                                              !2
         40        DO_FCALL                                      0  $22     
         41      > JMPZ                                                     $22, ->44
         42    >   QM_ASSIGN                                        ~23     !2
         43      > JMP                                                      ->45
         44    >   QM_ASSIGN                                        ~23     <array>
         45    >   ASSIGN                                                   !2, ~23
   22    46        COUNT                                            ~25     !1
         47        IS_SMALLER                                               1, ~25
         48      > JMPZ                                                     ~26, ->54
         49    >   INIT_FCALL_BY_NAME                                       'find_even'
         50        SEND_VAR_EX                                              !1
         51        DO_FCALL                                      0  $27     
         52        QM_ASSIGN                                        ~28     $27
         53      > JMP                                                      ->55
         54    >   QM_ASSIGN                                        ~28     !1
         55    >   ASSIGN                                                   !3, ~28
   23    56        COUNT                                            ~30     !2
         57        IS_SMALLER                                               1, ~30
         58      > JMPZ                                                     ~31, ->64
         59    >   INIT_FCALL_BY_NAME                                       'find_even'
         60        SEND_VAR_EX                                              !2
         61        DO_FCALL                                      0  $32     
         62        QM_ASSIGN                                        ~33     $32
         63      > JMP                                                      ->65
         64    >   QM_ASSIGN                                        ~33     !2
         65    >   ASSIGN                                                   !4, ~33
   25    66        INIT_FCALL                                               'array_merge'
         67        SEND_VAR                                                 !3
         68        SEND_VAR                                                 !4
         69        DO_ICALL                                         $35     
         70      > RETURN                                                   $35
   26    71*     > RETURN                                                   null

End of function find_even

Function has_even:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/EQtXT
function name:  has_even
number of ops:  18
compiled vars:  !0 = $numbers, !1 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'join'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        ECHO                                                     ~3
   36     7      > FE_RESET_R                                       $4      !0, ->15
          8    > > FE_FETCH_R                                               $4, !1, ->15
   37     9    >   MOD                                              ~5      !1, 2
         10        IS_IDENTICAL                                             ~5, 0
         11      > JMPZ                                                     ~6, ->14
   38    12    >   FE_FREE                                                  $4
         13      > RETURN                                                   <true>
   36    14    > > JMP                                                      ->8
         15    >   FE_FREE                                                  $4
   41    16      > RETURN                                                   <false>
   42    17*     > RETURN                                                   null

End of function has_even

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.95 ms | 1411 KiB | 22 Q