PHP Question

PHP : How to trim last string inside the loop

Is there other way to trim this inside the loop? I have a loop and inside, i need to rtrim the last loop row, but what happen is it removes all character each of the last right string.

If I use this method, it works.

$plus = "";
for($i=0; $i<6; $i++){
$plus .= 'total'.$i."+";
echo rtrim($plus,'+');

But how if i need to rtrim it inside the loop? Because I need for some reason

for($i=0; $i<6; $i++){
$plus = 'total'.$i."+";
echo rtrim($plus,'+');
//output says

//This should be like

Answer Source

That makes no sense. If you don't want the last + then rtrim() after the loop, why inside?

Just create an array and implode():

for($i=0; $i<6; $i++){
    $plus[] = 'total'.$i;

$plus = implode('+', $plus);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download