note 83464 modified in function.implode by danbrown

From: Date: Mon, 21 Jul 2008 17:05:40 +0000
Subject: note 83464 modified in function.implode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142434@lists.php.net to get a copy of this message
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> --was-- A usefull version of implode() when you need to surround values, for example when you are working with nodes (HTML, XML) 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> http://php.net/manual/en/function.implode.php

« previous php.notes (#142434) next »