note 85691 modified in function.implode by felipe
| From: | felipe@php.net | Date: | Sat, 13 Sep 2008 00:24:47 +0000 |
| Subject: | note 85691 modified in function.implode by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144383@lists.php.net to get a copy of this message | ||
Here's my version of the english implode function, it's quite crafty so I thought I'd
share it...
<?php
#
# Transforms an array to an english list:
# This, This and This
#
function array_to_english ( $list, $glueword='and' ) {
$string = false;
foreach ( array_reverse ( $list ) as $index=>$value ) {
$string = "$value$glue$string";
if ( $index == 0 ) $glue = " $glueword ";
if ( $index == 1 ) $glue = ', ';
}
return $string;
}
?>
--was--
Here's my version of the english implode function, it's quite crafty so I thought I'd
share it...
#
# Transforms an array to an english list:
# This, This and This
#
function array_to_english ( $list, $glueword='and' ) {
$string = false;
foreach ( array_reverse ( $list ) as $index=>$value ) {
$string = "$value$glue$string";
if ( $index == 0 ) $glue = " $glueword ";
if ( $index == 1 ) $glue = ', ';
}
return $string;
}
http://php.net/manual/en/function.implode.php