3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [0, 1, 2, 3, 4, 5, 6, 7]; $index = 3; // Result: 1, 2, 3, 4, 5. *example 1 echo pages($a, $index) . "\n"; $index = 0; // Result: 0, 1, 2, 3, 4. *example 2 echo pages($a, $index) . "\n"; $index = 7; // Result: 3, 4, 5, 6, 7. *example 3 echo pages($a, $index) . "\n"; $index = 6; // Result: 3, 4, 5, 6, 7. *example 4 echo pages($a, $index) . "\n"; function pages($a, $index){ if($index >= count($a)-2){ $start = count($a)-5; }elseif($index <=2){ $start = 0; }else{ $start = $index-2; } return implode(", ", array_slice($a, $start, 5)); }
Output for git.master, git.master_jit, rfc.property-hooks
1, 2, 3, 4, 5 0, 1, 2, 3, 4 3, 4, 5, 6, 7 3, 4, 5, 6, 7

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:
26.73 ms | 405 KiB | 5 Q