note 84788 deleted from function.implode by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 13:20:49 +0000 |
| Subject: | note 84788 deleted from function.implode by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189756@lists.php.net to get a copy of this message | ||
Note Submitter: mjong at magnafacta dot nl
----
Many of the functions below can be simplified using this short function:
<?php
function array_implode($arrays, &$target = array()) {
foreach ($arrays as $item) {
if (is_array($item)) {
array_implode($item, $target);
} else {
$target[] = $item;
}
}
return $target;
}
$a = array('a', 'b', array('c', 'd', array('e'),
'f'), 'g', array('h'));
echo join(' - ', array_implode($a));
?>
The outputs:
<?php
a - b - c - d - e - f - g - h
?>