note 103825 added to function.implode
| From: | PatrickvanderLeer at tmaatwebsite dot nl | Date: | Thu, 05 May 2011 10:16:38 +0000 |
| Subject: | note 103825 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179448@lists.php.net to get a copy of this message | ||
Wrote my own function to format a string correctly in human language, in my case dutch. I know it
has been written as shown in comments below but you can't have too much ways to accomplish your
goals.
<?php
function formatArr2Str($arr, $glue=', ', $fglue=' en ') {
if(!empty($arr) && is_array($arr)) {
$return=''; $j=(count($arr)-1);
for($i=0;$i<=$j;$i++){
if($i==($j-1)){
if(!empty($fglue)){
$return .= $arr[$i].$fglue;
} else {
$return .= $arr[$i].$glue;
}
}elseif($i<=($j-2)){
$return .= $arr[$i].$glue;
} else {
$return .= $arr[$i];
}
}
return $return;
} else {
return false;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.151.216.36
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- https://master.php.net/note/edit/103825
Del: integrated -- https://master.php.net/note/delete/103825/integrated
Del: useless -- https://master.php.net/note/delete/103825/useless
Del: bad code -- https://master.php.net/note/delete/103825/bad+code
Del: spam -- https://master.php.net/note/delete/103825/spam
Del: non-english -- https://master.php.net/note/delete/103825/non-english
Del: in docs -- https://master.php.net/note/delete/103825/in+docs
Del: other reasons-- https://master.php.net/note/delete/103825
Reject -- https://master.php.net/note/reject/103825
Search -- https://master.php.net/manage/user-notes.php