Page 1 of 1
Christmas tree
Posted: Tue Dec 06, 2011 11:04 am
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
Re: Christmas tree
Posted: Tue Dec 06, 2011 11:15 am
by Celauran
What have you done so far? What problems are you encountering?
Re: Christmas tree
Posted: Tue Dec 06, 2011 1:17 pm
by Dvargas
Everything i just can't do it
Re: Christmas tree
Posted: Tue Dec 06, 2011 1:34 pm
by Celauran
So you've tried nothing and you want us to do your homework for you? Sorry, no.
Re: Christmas tree
Posted: Tue Dec 06, 2011 2:11 pm
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...
Re: Christmas tree
Posted: Wed Dec 07, 2011 2:11 am
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 " ";
for($j=0;$j<(2*$i)-1;$j++)
echo "*";
echo "<br />";
}
?>
Re: Christmas tree
Posted: Wed Dec 07, 2011 8:59 am
by twinedev
no need for the two inner loops, just use str_repeat()
Re: Christmas tree
Posted: Wed Dec 07, 2011 9:30 am
by maxx99
Nah

its no fun and christmas is all about fun!
