PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
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"; } }
Show:  
Copy Clear