note 86845 added to function.implode
| From: | pr at technoparkcorp dot com | Date: | Thu, 06 Nov 2008 08:48:22 +0000 |
| Subject: | note 86845 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146199@lists.php.net to get a copy of this message | ||
This function is much more elegant and fast. It converts array to the list with 'and' at
the end:
function ImplodeToEnglish ($array) {
// sanity check
if (!$array || !count ($array))
return '';
// get last element
$last = array_pop ($array);
// if it was the only element - return it
if (!count ($array))
return $last;
return implode (', ', $array).' and '.$last;
}
----
Server IP: 69.147.83.197
Probable Submitter: 92.251.66.176 (proxied: 92.251.66.176)
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- https://master.php.net/note/edit/86845
Del: integrated -- https://master.php.net/note/delete/86845/integrated
Del: useless -- https://master.php.net/note/delete/86845/useless
Del: bad code -- https://master.php.net/note/delete/86845/bad+code
Del: spam -- https://master.php.net/note/delete/86845/spam
Del: non-english -- https://master.php.net/note/delete/86845/non-english
Del: in docs -- https://master.php.net/note/delete/86845/in+docs
Del: other reasons-- https://master.php.net/note/delete/86845
Reject -- https://master.php.net/note/reject/86845
Search -- https://master.php.net/manage/user-notes.php