Page 1 of 2

PHP QUESTION

Posted: Tue Sep 29, 2009 12:48 pm
by gentooF1
Hi!
there i need some help with two different things..
i need to print out a triangle that looks like this one:
******
*****
****
***
**
*

******
*****
****
***
**
*

I know that i have to play with FOR loops.
Can anyone help me and write it in PHP.

Code: Select all

<html>
<body>
 
<?php
for ($i=1; $i<=5; $i++)
//for ($j=i+1; $j<=5; $j++)
echo "*" ;
echo "<br>";
for ($j=1; $i<=9; $i++)
 
echo "*" ;
echo "<br>";
 
?>
 
</body>
</html>
REALLY DO NOT KNOW HOW TO DO.... SO PLEASE TELL ME WHERE TO POST IT IF THIS IS NOT CORRECT SITE.

Re: PHP QUESTION

Posted: Tue Sep 29, 2009 2:35 pm
by arjan.top

Code: Select all

 
for($i=0; $i<6; $i++) {
        for($j=$i; $j<6; $j++) {
                echo "*";
        }
        echo "\n";
}
 

Re: PHP QUESTION

Posted: Tue Sep 29, 2009 3:09 pm
by gentooF1

Code: Select all

<html>
<body>
 
<?php
 
for($i=0; $i<6; $i++) {
    for($j=$i; $j<6; $j++) {
        echo "*";
    }
        echo "<br/>";
}
?>
 
</body>
</html>

It is a really corect output! This bellow it is correct from code upstars... THANK YOU
******
*****
****
***
**
*

Re: PHP QUESTION

Posted: Tue Sep 29, 2009 3:23 pm
by gentooF1
I would like to know what to do for others combinations, let's say the one like bellow:

Code: Select all

 
    *
   ***
  *****
 *******
*********
 
And now, what are the for cases... ?Anyone know?

Re: PHP QUESTION

Posted: Tue Sep 29, 2009 5:41 pm
by pickle
Is this a homework assignment?


Also, I've moved this thread to PHP - Code. Please check all the forums before posting to make sure you put it in the right spot.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 8:06 am
by gentooF1
No, this is the excersise that I have to do for my new work... So please help me... !

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 9:44 am
by pickle
Your work hired you as a PHP developer and are asking you to do something like this? Seems a bit odd.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 9:47 am
by jackpf
pickle wrote:Your work hired you as a PHP developer and are asking you to do something like this? Seems a bit odd.
lol yeah. You get paid to draw triangles? Nice...

And the title of this thread sucks. It applies to like...probably about 75% of posts on this forum.

Posted: Wed Sep 30, 2009 10:08 am
by HavokDelta6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 2:30 pm
by AlexC
An easier way:

Code: Select all

<?php
for( $i = 10; $i > 0; $i-- ) {
echo str_repeat( '*', $i )."\n";
}
?>
 

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 2:54 pm
by califdon
gentooF1 wrote:No, this is the excersise that I have to do for my new work... So please help me... !
You need to explain this. I never heard of an employer who pays someone to do exercises.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 4:30 pm
by Mirge
califdon wrote:
gentooF1 wrote:No, this is the excersise that I have to do for my new work... So please help me... !
You need to explain this. I never heard of an employer who pays someone to do exercises.
Yeah.......seriously.. who is going to invest time and money into someone just to have them draw pointless shapes heh.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 4:35 pm
by CodeGeek
Who cares he's getting paid for it? Getting paid is a good thing, last time I checked.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 4:42 pm
by Mirge
CodeGeek wrote:Who cares he's getting paid for it? Getting paid is a good thing, last time I checked.
Doesn't sound like a job to me.. sounds like an assignment. I think that's what people are getting at.

Re: PHP QUESTION

Posted: Wed Sep 30, 2009 5:20 pm
by peterjwest
How the hell is he employed? I could do this in my sleep, I have a first class degree and I still can't get employed.