3v4l.org

run code in 300+ PHP versions simultaneously
<?php // array of authors, number of authors to take first function niceAuthorsPrint(array $authors, $takeCount){ $totalAuthors = count( $authors ); if($totalAuthors >= 3 && $takeCount >= $totalAuthors) { $takeCount = 2; } if($totalAuthors == 2 && $takeCount >= $totalAuthors) { $takeCount = 1; } $last = array_pop($authors); $tailCount = $totalAuthors - $takeCount; $first = array_slice($authors, 0, $takeCount); $othersLabel = $tailCount == 1 ? $last : $tailCount . ' others'; $string = implode( ", ", $first ); if($tailCount > 0){ $string .= " and " . $othersLabel; } return $string; } // take 3 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 3) ."\n"; // take 4 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 4) ."\n"; // take 5 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 5) ."\n"; // take original count, take first three as default echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 5) ."\n"; // take original count, take first three as default echo niceAuthorsPrint(array( 'user1', 'user2', 'user3'), 3) ."\n"; // take original count, take first three as default echo niceAuthorsPrint(array( 'user1', 'user2'), 2) ."\n";
Output for git.master, git.master_jit, rfc.property-hooks
user1, user2, user3 and 2 others user1, user2, user3, user4 and user5 user1, user2 and 3 others user1, user2 and 3 others user1, user2 and user3 user1 and user2

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