note 73985 added to function.implode

From: Date: Mon, 19 Mar 2007 22:52:30 +0000
Subject: note 73985 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-124605@lists.php.net to get a copy of this message
And adding one more case to drewish at katherinehouse dot com's code to deal with the two-element case "a and b": <?php case 2: return reset($array).' and '.end($array); ?> Of course, then one can start considering Oxford rules again, and maybe testing that the argument really is an array.... <?php function english_list($array, $useOxfordComma=false) { if(!is_array($array)) return ''; switch(count($array)) { case 0: return ''; case 1: // This may not be a normal numerically-indexed array. return reset($array); case 2: return reset($array).' and '.end($array); default: $last = array_pop($array); return implode(', ', $array).($useOxfordComma?',':'').' and '.$last; } } ?> ---- Server IP: 203.89.181.184 Probable Submitter: 60.234.168.92 ---- Manual Page -- http://www.php.net/manual/en/function.implode.php Edit -- https://master.php.net/note/edit/73985 Del: integrated -- https://master.php.net/note/delete/73985/integrated Del: useless -- https://master.php.net/note/delete/73985/useless Del: bad code -- https://master.php.net/note/delete/73985/bad+code Del: spam -- https://master.php.net/note/delete/73985/spam Del: non-english -- https://master.php.net/note/delete/73985/non-english Del: in docs -- https://master.php.net/note/delete/73985/in+docs Del: other reasons-- https://master.php.net/note/delete/73985 Reject -- https://master.php.net/note/reject/73985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124605) next »