3v4l.org

run code in 300+ PHP versions simultaneously
<?php function x_the_image( $post_id ) { $attachment_ids = array( 1, 2, 3, 4 ); $next_id = -1; foreach ( $attachment_ids as $idx => $attachment_id ) { if ( $attachment_id == $post_id ) { $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ]; break; } } return $next_id; } var_dump( x_the_image(2) === 3, x_the_image(3) === 4, x_the_image(4) === 1, x_the_image(5) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2SPQf
function name:  (null)
number of ops:  22
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'x_the_image'
          2        SEND_VAL                                                 2
          3        DO_FCALL                                      0  $0      
          4        IS_IDENTICAL                                     ~1      $0, 3
          5        SEND_VAL                                                 ~1
          6        INIT_FCALL                                               'x_the_image'
          7        SEND_VAL                                                 3
          8        DO_FCALL                                      0  $2      
          9        IS_IDENTICAL                                     ~3      $2, 4
         10        SEND_VAL                                                 ~3
         11        INIT_FCALL                                               'x_the_image'
         12        SEND_VAL                                                 4
         13        DO_FCALL                                      0  $4      
         14        IS_IDENTICAL                                     ~5      $4, 1
         15        SEND_VAL                                                 ~5
         16        INIT_FCALL                                               'x_the_image'
         17        SEND_VAL                                                 5
         18        DO_FCALL                                      0  $6      
         19        SEND_VAR                                                 $6
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function x_the_image:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
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 = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
Branch analysis from position: 15
filename:       /in/2SPQf
function name:  x_the_image
number of ops:  18
compiled vars:  !0 = $post_id, !1 = $attachment_ids, !2 = $next_id, !3 = $attachment_id, !4 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, -1
    6     3      > FE_RESET_R                                       $7      !1, ->15
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->15
          5    >   ASSIGN                                                   !4, ~8
    7     6        IS_EQUAL                                                 !3, !0
          7      > JMPZ                                                     ~10, ->14
    8     8    >   ADD                                              ~11     !4, 1
          9        COUNT                                            ~12     !1
         10        MOD                                              ~13     ~11, ~12
         11        FETCH_DIM_R                                      ~14     !1, ~13
         12        ASSIGN                                                   !2, ~14
    9    13      > JMP                                                      ->15
    6    14    > > JMP                                                      ->4
         15    >   FE_FREE                                                  $7
   12    16      > RETURN                                                   !2
   13    17*     > RETURN                                                   null

End of function x_the_image

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.38 ms | 1407 KiB | 19 Q