note 52398 added to function.implode

From: Date: Fri, 29 Apr 2005 14:20:54 +0000
Subject: note 52398 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-88754@lists.php.net to get a copy of this message
Correction: I meant "passed by value", not "pass by reference". My mistake. Passing by reference would speed up any of these functions by avoiding the copy necessary for "by value. Other solutions have problems with non-arrays as well. But it demonstrates that there are many ways to solve this problem. Adding checks for non-arrays and short arrays makes the solution less elegant, but safer. Other solutions should have included similar protections. function english_list($array, $oxfordComma=0) { if (!is_array($array)) return $array; if (count($array) <= 1) return join(", ", $array); $last = array_pop($array); return join(", ", $array) . ($oxfordComma ? "," : "") . " and " . $last; } ---- Manual Page -- http://www.php.net/manual/en/function.implode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52398 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52398&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52398&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52398&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52398&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52398&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52398&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88754) next »