Human Readable List From Array


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // ex: human_list(array('one', 'two', 'three)) --> one, two, and three
  2. function human_list($itemList) {
  3. switch(count($itemList)) {
  4. case 0: return '';
  5. case 1: return $itemList[0];
  6. default:
  7. $last = array_pop($itemList);
  8. return implode(', ', $itemList).' and '.$last;
  9. }
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.