<?
function itemlist($array, $delimiter = ", ", $last = "and", $limit = false, $summarize = false){
$last = lp($last, "L");
if (!is_array($array)) return false;
if ($c = count($array)){
if ($c > 2){
$limit = $limit ?: count($array);
if ($summarize === true && $limit !== false && $limit < $c){
$items = join($delimiter, array_slice($array, 0, $limit));
$summary = lp("and", "L") . SPACE . count(array_slice($array, $limit, $c - 1)) . SPACE . lp("more:3", "L");
return $items . SPACE . $summary;
}
return join($delimiter, array_slice($array, 0, $limit - 1)) . " $last " . $array[$limit - 1];
} else {
return join(" $last ", $array);
}
} else {
return false;
}
}
?>
Note that the code is the exact code that I am using and may use functions that are exclusive to my system, and as such may not be suitable for copy/paste. Plus, these functions can change at any time and any blogs/tutorials that depend on these functioning in a specific way may have changed since it was written. If such a discrepancy is found, please email me at
If the function "lp()" is used, it's my "Language Print" function, that translates phrases from english to the site language. So, instead of "lp('and')" you would use just "and".
If the function "lp()" is used, it's my "Language Print" function, that translates phrases from english to the site language. So, instead of "lp('and')" you would use just "and".