Skip to content

Instantly share code, notes, and snippets.

@stevenliebregt
Last active July 30, 2018 12:54
Show Gist options
  • Save stevenliebregt/ef311d7c6a90964be651287b4477eb95 to your computer and use it in GitHub Desktop.
Save stevenliebregt/ef311d7c6a90964be651287b4477eb95 to your computer and use it in GitHub Desktop.
list, comma & and @ end
<?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