3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_prime($n) { if ($n <= 1) { return false; } elseif ($n <= 3) { return true; } elseif (($n % 2 == 0) || ($n % 3 == 0)) { return false; } $i = 5; while ($i * $i <= $n) { if (($n % $i == 0) || ($n % ($i + 2) == 0)) { return false; $i = $i + 6; } } return true; } function prime_gen() { for($x=0; $x< PHP_INT_MAX; $x++) { if(is_prime($x)){ yield $x; } } } function nth_prime($n) { $nth = 0; foreach (prime_gen() as $prime) { if (++$nth >= $n) { break; } } return $prime; } echo nth_prime(9);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BXKIe
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'nth_prime'
          1        SEND_VAL                                                 9
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function is_prime:
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 = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 19
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 26
Branch analysis from position: 15
filename:       /in/BXKIe
function name:  is_prime
number of ops:  35
compiled vars:  !0 = $n, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        IS_SMALLER_OR_EQUAL                                      !0, 1
          2      > JMPZ                                                     ~2, ->5
    5     3    > > RETURN                                                   <false>
          4*       JMP                                                      ->17
    6     5    >   IS_SMALLER_OR_EQUAL                                      !0, 3
          6      > JMPZ                                                     ~3, ->9
    7     7    > > RETURN                                                   <true>
          8*       JMP                                                      ->17
    8     9    >   MOD                                              ~4      !0, 2
         10        IS_EQUAL                                         ~5      ~4, 0
         11      > JMPNZ_EX                                         ~5      ~5, ->15
         12    >   MOD                                              ~6      !0, 3
         13        IS_EQUAL                                         ~7      ~6, 0
         14        BOOL                                             ~5      ~7
         15    > > JMPZ                                                     ~5, ->17
    9    16    > > RETURN                                                   <false>
   12    17    >   ASSIGN                                                   !1, 5
   13    18      > JMP                                                      ->30
   14    19    >   MOD                                              ~9      !0, !1
         20        IS_EQUAL                                         ~10     ~9, 0
         21      > JMPNZ_EX                                         ~10     ~10, ->26
         22    >   ADD                                              ~11     !1, 2
         23        MOD                                              ~12     !0, ~11
         24        IS_EQUAL                                         ~13     ~12, 0
         25        BOOL                                             ~10     ~13
         26    > > JMPZ                                                     ~10, ->30
   15    27    > > RETURN                                                   <false>
   16    28*       ADD                                              ~14     !1, 6
         29*       ASSIGN                                                   !1, ~14
   13    30    >   MUL                                              ~16     !1, !1
         31        IS_SMALLER_OR_EQUAL                                      ~16, !0
         32      > JMPNZ                                                    ~17, ->19
   19    33    > > RETURN                                                   <true>
   20    34*     > RETURN                                                   null

End of function is_prime

Function prime_gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
Branch analysis from position: 8
filename:       /in/BXKIe
function name:  prime_gen
number of ops:  12
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   GENERATOR_CREATE                                         
   23     1        ASSIGN                                                   !0, 0
          2      > JMP                                                      ->9
   24     3    >   INIT_FCALL                                               'is_prime'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->8
   25     7    >   YIELD                                                    !0
   23     8    >   PRE_INC                                                  !0
          9    >   IS_SMALLER                                               !0, 9223372036854775807
         10      > JMPNZ                                                    ~5, ->3
   28    11    > > GENERATOR_RETURN                                         

End of function prime_gen

Function nth_prime:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
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: 10
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
Branch analysis from position: 11
filename:       /in/BXKIe
function name:  nth_prime
number of ops:  14
compiled vars:  !0 = $n, !1 = $nth, !2 = $prime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        ASSIGN                                                   !1, 0
   33     2        INIT_FCALL                                               'prime_gen'
          3        DO_FCALL                                      0  $4      
          4      > FE_RESET_R                                       $5      $4, ->11
          5    > > FE_FETCH_R                                               $5, !2, ->11
   34     6    >   PRE_INC                                          ~6      !1
          7        IS_SMALLER_OR_EQUAL                                      !0, ~6
          8      > JMPZ                                                     ~7, ->10
   35     9    > > JMP                                                      ->11
   33    10    > > JMP                                                      ->5
         11    >   FE_FREE                                                  $5
   39    12      > RETURN                                                   !2
   41    13*     > RETURN                                                   null

End of function nth_prime

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
210.45 ms | 1407 KiB | 16 Q