Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

need help with simple for loop new to PHP and forum

General discussions related to php

Moderators: macek, egami, gesf

need help with simple for loop new to PHP and forum

Postby ak4744710 » Fri Feb 08, 2013 11:34 pm

I need to figure out how to make 5 rows of * and only use one for loop it has been driving me nuts all week any help is greatly appreciated because I have tried so many different ways. I am trying to create this but with only one for loop in php *
**
***
****
*****
ak4744710
New php-forum User
New php-forum User
 
Posts: 4
Joined: Fri Feb 08, 2013 11:29 pm

Re: need help with simple for loop new to PHP and forum

Postby ak4744710 » Fri Feb 08, 2013 11:35 pm

*
**
***
****
*****
is how it should look
ak4744710
New php-forum User
New php-forum User
 
Posts: 4
Joined: Fri Feb 08, 2013 11:29 pm

Re: need help with simple for loop new to PHP and forum

Postby php9 » Fri Feb 22, 2013 2:41 am

That's pretty easy if you know which function to use. In order to do it in only one loop, you'll need to use the str_repeat() function. Here's the code:

Code: Select all
for($i=1; $i<6; $i++)
{
    echo str_repeat('*', $i) . "<br />";
}


This will show the desired output on a page.
php9
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Feb 22, 2013 2:20 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.