Last active
April 28, 2024 09:26
-
-
Save SleeplessByte/4514697 to your computer and use it in GitHub Desktop.
Creates a human readable list of an array, implodes all items, but combines last two first.
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 | |
/** | |
* Creates a human readable list of an array | |
* | |
* @param string[] $ranges array to list items of | |
* @param string $glue normal glue between items | |
* @param string $last glue between last two items | |
* | |
* @remarks works with 0, 1, 2 or 3+ items | |
* @returns string 'item1, item2, item3 or item4' | |
*/ | |
function array_listing( $ranges, $glue = ', ', $last = ' or ') { | |
array_splice( $ranges, -2, 2, implode( $last, array_slice( $ranges, -2, 2 ) ) ); | |
return implode( $glue , $ranges ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment