- var_dump: documentation ( source)
<?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) );