note 83464 deleted from function.implode by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 13:20:21 +0000 |
| Subject: | note 83464 deleted from function.implode by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189752@lists.php.net to get a copy of this message | ||
Note Submitter: mr dot bloar at gmail dot com
----
A usefull version of implode() when you need to surround values, for example when you are working
with nodes (HTML, XML)
<?php
function myImplode($before, $after, $glue, $array){
$nbItem = count($array);
$i = 1;
foreach($array as $item){
if($i < $nbItem){
$output .= "$before$item$after$glue";
}else $output .= "$before$item$after";
$i++;
}
return $output;
}
$an_array = array('value1','value2');
print myImplode("<a href=\"#\">","</a>"," >
", $an_array);
?>
output : <a href="#">value1</a> > <a
href="#">value2</a>