Return to Snippet

Revision: 31148
at August 31, 2010 01:44 by iloveitaly


Initial Code
// ex: human_list(array('one', 'two', 'three)) --> one, two, and three
function human_list($itemList) {
	switch(count($itemList)) {
		case 0: return '';
		case 1: return $itemList[0];
		default:
			$last = array_pop($itemList);
			return implode(', ', $itemList).' and '.$last;
	}
}

Initial URL


Initial Description


Initial Title
Human Readable List From Array

Initial Tags
list

Initial Language
PHP