note 84604 rejected from function.implode by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Jul 2008 17:05:06 +0000 |
| Subject: | note 84604 rejected from function.implode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142432@lists.php.net to get a copy of this message | ||
Note Submitter: morticae at example dot com
----
re: m dot ford
Sorry to be picky, but your solution doesn't account for the base-case empty array.
If you called:
implode_array('before', 'after', 'glue', array());
you would get:
'before after'
<?php
function implode_wrapped($before, $after, $glue, $array) {
if(!empty($array)){
return $before . implode($after.$glue.$before, $array) . $after;
}
return '';
}
?>
Webmaster's solution works because substr will return an empty string instead of an error.
This is not the case in all languages.