note 26211 added to function.explode
| From: | jeremy at fishbowlrecords dot com | Date: | Tue, 22 Oct 2002 16:58:32 +0000 |
| Subject: | note 26211 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38425@lists.php.net to get a copy of this message | ||
Thanks peter at int8 dot com for the functions. I did make one change though.
function double_implode($first_break, $second_break, $array)
{
$string = "";
$k=0;
$num_length = count($array);
foreach ($array as $key => $value)
{
// if the element of the main array is an array
if (is_array($array[$key]))
{
// append the string of the converted arary to
// the string being constructed of the whole
// main array
$string .= implode($second_break, $array[$key]);
}
else
{
// append the element to the string
$string .= $array[$key];
}
$k++;
//change here!
// append the delimiting character to the string
if ($k<$num_length)
$string .= $first_break;
}
return $string;
}
______________
Notice the "if ($k<$num_length)" check near the bottom. What I found is that without
that, any string created would have an extra character at the end, and when exploded would have an
extra (empty) array cell at the end. So, now I can do something like
if ($arraybeforeimplode==$arrayafterexplode)
and they will be equal, whereas before they would test as not being equal. I hope that made sense.
Thanks!
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+26211
http://master.php.net/manage/user-notes.php?action=delete+26211
http://master.php.net/manage/user-notes.php?action=reject+26211