3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays[] = array(); $arrays[] = array('user1'); $arrays[] = array('user1', 'user2'); $arrays[] = array('user1', 'user2', 'user3'); $arrays[] = array('user1', 'user2', 'user3', 'user4'); $arrays[] = array('user1', 'user2', 'user3', 'user4', 'user5'); foreach ($arrays as $i => $array) { echo "TEST $i: "; $count = sizeof($array); if ($count < 3) { echo implode(' and ', $array); } else { if ($count == 3) { $array[2] = "and {$array[2]}"; } elseif ($count > 3) { $more = $count - 3; array_splice($array, 3, $more, ["and $more other" . ($more > 1 ? 's' : '')]); } echo implode(', ', $array); } echo "\n---\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
TEST 0: --- TEST 1: user1 --- TEST 2: user1 and user2 --- TEST 3: user1, user2, and user3 --- TEST 4: user1, user2, user3, and 1 other --- TEST 5: user1, user2, user3, and 2 others ---

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