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) );
Output for git.master, git.master_jit, rfc.property-hooks
bool(true) bool(true) bool(true) int(-1)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
31.04 ms | 401 KiB | 8 Q