Christmas tree

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
Dvargas
Forum Newbie
Posts: 2
Joined: Tue Dec 06, 2011 10:56 am

Christmas tree

Post by Dvargas »

Good afternoon

I have an avaliution tomorrow and have to do a Christmas tree using PHP with this symbol -----> *


Can anybody help me?Please

i'm running out of time
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Christmas tree

Post by Celauran »

What have you done so far? What problems are you encountering?
Dvargas
Forum Newbie
Posts: 2
Joined: Tue Dec 06, 2011 10:56 am

Re: Christmas tree

Post by Dvargas »

Everything i just can't do it
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Christmas tree

Post by Celauran »

So you've tried nothing and you want us to do your homework for you? Sorry, no.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Christmas tree

Post by twinedev »

Code: Select all

echo " ***  *   * ****  *****  ***  ***** *   *   *    ***       ***** ****  ***** *****\n";
echo "*   * *   * *   *   *   *   *   *   ** **  * *  *   *        *   *   * *     *    \n";
echo "*     *   * *   *   *   *       *   * * * *   * *            *   *   * *     *    \n";
echo "*     ***** ****    *    ***    *   *   * *****  ***         *   ****  ****  **** \n";
echo "*     *   * * *     *       *   *   *   * *   *     *        *   * *   *     *    \n";
echo "*   * *   * *  *    *   *   *   *   *   * *   * *   *        *   *  *  *     *    \n";
echo " ***  *   * *   * *****  ***    *   *   * *   *  ***         *   *   * ***** *****\n"; 
There ya go. With the limited info you gave, that solves your problem. Of course, since you tried "everything" you already tried it...
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Christmas tree

Post by maxx99 »

Code: Select all

              *
             ***
            *****
           *******
          *********
         ***********
        *************
       ***************
      *****************
     *******************
    *********************
   ***********************
  *************************
 ***************************
Or like this :)

Code: Select all

<?php
$levels = 15;
for($i=0;$i<$levels;$i++){
	for($j=0;$j<floor(($levels-$i));$j++)
		echo "&nbsp;";
	for($j=0;$j<(2*$i)-1;$j++)
		echo "*";

	echo "<br />";
}
?>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Christmas tree

Post by twinedev »

no need for the two inner loops, just use str_repeat()
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Christmas tree

Post by maxx99 »

Nah :D its no fun and christmas is all about fun! :)
Post Reply