Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // always make such numbers configurable $num_lookaheads = 5; // test array $images = [1,2,3,4]; // limit the number of lookaheads if array is too small $limit = min($num_lookaheads, count($images)); foreach ($images as $position => $value) { // current item echo $value,"\n"; // getting look-aheads // taking the missing items from the beginning $beginning = 0; for($i = 1; $i < $limit; $i++) { $ahead = $images[$position + $i] ?? $images[$beginning++]; echo " ", $ahead,"\n"; } }
Copy Clear