PHP QUESTION

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

gentooF1
Forum Newbie
Posts: 4
Joined: Tue Sep 29, 2009 12:43 pm

PHP QUESTION

Post 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.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: PHP QUESTION

Post by arjan.top »

Code: Select all

 
for($i=0; $i<6; $i++) {
        for($j=$i; $j<6; $j++) {
                echo "*";
        }
        echo "\n";
}
 
gentooF1
Forum Newbie
Posts: 4
Joined: Tue Sep 29, 2009 12:43 pm

Re: PHP QUESTION

Post 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
******
*****
****
***
**
*
gentooF1
Forum Newbie
Posts: 4
Joined: Tue Sep 29, 2009 12:43 pm

Re: PHP QUESTION

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP QUESTION

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
gentooF1
Forum Newbie
Posts: 4
Joined: Tue Sep 29, 2009 12:43 pm

Re: PHP QUESTION

Post by gentooF1 »

No, this is the excersise that I have to do for my new work... So please help me... !
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP QUESTION

Post by pickle »

Your work hired you as a PHP developer and are asking you to do something like this? Seems a bit odd.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP QUESTION

Post 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.
HavokDelta6
Forum Newbie
Posts: 16
Joined: Mon Sep 28, 2009 4:11 pm

Post by HavokDelta6 »

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Last edited by HavokDelta6 on Tue Mar 20, 2012 5:58 am, edited 1 time in total.
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Re: PHP QUESTION

Post by AlexC »

An easier way:

Code: Select all

<?php
for( $i = 10; $i > 0; $i-- ) {
echo str_repeat( '*', $i )."\n";
}
?>
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP QUESTION

Post 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.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: PHP QUESTION

Post 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.
CodeGeek
Forum Newbie
Posts: 12
Joined: Wed Sep 30, 2009 3:36 pm
Location: England

Re: PHP QUESTION

Post by CodeGeek »

Who cares he's getting paid for it? Getting paid is a good thing, last time I checked.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: PHP QUESTION

Post 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.
peterjwest
Forum Commoner
Posts: 63
Joined: Tue Aug 04, 2009 1:06 pm

Re: PHP QUESTION

Post 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.
Post Reply