Posted By

iloveitaly on 08/31/10


Tagged

list human formatted


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

googooster


Human Readable List From Array


 / Published in: PHP
 

  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  

You need to login to post a comment.