deleting white space at the end of for loop output in php -


can body me how can delete white space @ end of output. might easy question honest took me more 45 minutes , still nothing. assignment

write php script prints numbers number inputted on form zero. numbers should separated single space last number, zero, should not have space after it. if user inputs number smaller zero, print “the number should @ least zero!” used form looks this:

luku:

example output

5 4 3 2 1 0

my code:

     <?php  $number=$_get["number"];    if ($number < 0){    echo "the number should @ least zero!";  } else {   for($i=$number; $i>=0; $i=$i-1) { echo $i." ";  }  }  ?>  

you can use trim()

<?php    $number=$_get["number"];     if ($number < 0){       echo "the number should @ least zero!";    } else {       $num = '';       for($i=$number; $i>=0; $i=$i-1)       {          $num .= $i." ";       }       echo trim($num);     }     ?>  

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -