keymasterviriya1150

Pyramid with One Loop

Aug 17th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3.     $n=8;
  4.     $t=50;
  5.     $ar= array(
  6.     "1"=>"1",
  7.     "2"=>"22",
  8.     "3"=>"333",
  9.     "4"=>"4444",
  10.     "5"=>"55555",
  11.     "6"=>"666666",
  12.     "7"=>"7777777",
  13.     "8"=>"88888888",
  14.     "9"=>"999999999", );
  15.     $i=1;
  16.     $sw=false;
  17.  
  18.     while(1)
  19.     {
  20.         if($i<=$n)
  21.         {
  22.             echo $ar[$i].'<br>';
  23.             $i++;
  24.         }
  25.         else if($i>=$n)
  26.         {
  27.             if($sw==false)
  28.             {
  29.                 $n--;
  30.                 $i=$n;
  31.                 $sw=true;
  32.             }
  33.             else if($sw==true && $n>0)
  34.             {
  35.                 echo $ar[--$n].'<br>';
  36.             }
  37.             else
  38.                 break;
  39.         }
  40.     }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment