Last active
July 30, 2018 12:54
-
-
Save stevenliebregt/ef311d7c6a90964be651287b4477eb95 to your computer and use it in GitHub Desktop.
list, comma & and @ end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$list = [1, 2, 3, 4]; | |
array_splice($list, -2, 2, implode(' and ', array_slice($list, -2))); | |
$text = implode(', ', $list); | |
echo $text; // This will print "1, 2, 3 and 4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment