Search code examples
phpattributesspacing

Simplest way to fix variables spacing? [php]


I'm trying to create a very basic multiplication table without the actual table element, but not sure how to space the numbers correctly (without using css or an html table!). What's the simplest way to do this?

<?php

  for ($i=1; $i < 11 ; $i++) {

    for ($x=1; $x< 11 ; $x++) {
      echo  $i*$x . " ";
    }
    echo "<br>";
  }

 ?>


Solution

  • Is this good enough

    >     <?php for ($i=1; $i < 11 ; $i++) {
    >     for ($x=1; $x< 11 ; $x++) {
    >         $output = $i*$x;
    >         if($output >= 10){
    >             echo $output . str_repeat('&nbsp;', 4);
    >         } else{
    >             echo $output .  str_repeat('&nbsp;', 6); ;
    >         }
    >     }
    >     echo "<br>"; } ?>
    
    OUTPUT
    

    enter image description here