As noted, I would store in an array then implode() the stored array.
<?php
reset($values);
while($value = current($values)) {
// Remove # here, just store values
$array[] = $value;
next($values);
}
// Check that values have been stored
if(isset($array) && !empty($array))
// Implode with the # character
echo implode("#",$array);
?>
EDIT:
Since the #
is already stored in your values, you could use count()
and str_replace()
:
<?php
// Dummy array maker
for($a=1;$a<=10;$a++)
$values[] = $a.'#';
// Count how many are in array
$count = count($values);
reset($values);
$i = 1;
while($value = current($values)) {
// If the count is equal to the $i, remove #
echo ($i == $count)? str_replace("#","",$value) : $value;
next($values);
$i++;
}
?>
Gives you:
1#2#3#4#5#6#7#8#9#10