Jump to content

nested loops making pattern


eddieadams

Recommended Posts

depending on what you're really wanting to do with this, it might have to be altered a bit, but the hard part is there.

 

<?php
  $num = 5;
  $pos = 1;
  for ($a = 1; $a <= $num; $a++) {
    while ($pos <= $num) {
      for ($b = $a; $b <= $pos; $b++) {
        echo $b;
      }
      echo "<br/>";
      $pos++;
    }
    $pos = 1;
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.