[SOLVED] How to output something like this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mray
Forum Newbie
Posts: 4
Joined: Sat Aug 05, 2006 7:13 am

[SOLVED] How to output something like this

Post by mray »

Hello all.. Been following alot of PHPDN forum posts but just got the time to join.

So I got asked to output result like this in object oriented way.

Code: Select all

*
**
***
****
In a slight look, I thought that must be not to hard. Just construct a loop function or so and it would be done in a sec.. Unfortunately I feel my brain not working today. Been spending an hour with no result.. Im stuck.. :( so any hint on what should I do/modify would be greatly appreciated. I thought I have passed the basic of PHP and can move on to more advance level.. I am so embarased to myself I cant even output that.

My last minute code

Code: Select all

class stars {
      var $star;
      var $max;
      function throwStars(){
            for($i=0; $i<=$this->max; $i++){
                  for($a=$i; $a<$this->max; $a++){
                        echo $this->star;
                  }
                  echo '<br />';
            }
      }
}

$test = new stars;
$test->star='a';
$test->max=3;
$test->throwStars();
with last minute result..

Code: Select all

aaa
aa
a
Last edited by mray on Sat Aug 05, 2006 8:59 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

for($a = 0; $a < $i;  ++$a)
mray
Forum Newbie
Posts: 4
Joined: Sat Aug 05, 2006 7:13 am

Post by mray »

THX feyd! :)
Post Reply