answersLogoWhite

0

How do you create a loop using PHP?

Updated: 9/16/2023
User Avatar

Wiki User

14y ago

Best Answer

There are a number of different ways to loop using PHP. They're as follows:

  • For
  • Foreach
  • While
  • Do-while

Below are some examples of how each of these types of loop work.

For

for ($x = 0; $x < 100; $x++) {

echo $x.'
';

}

?>

Foreach

$array = array(1, 5, 8, 2, 9);

foreach ($array as $number) {

echo $number.'
';

}

?>

While

while ($x < 10) {

$x++;

echo $x.'
';

}

?>

Do-while

do {

$x++;

echo $x.'
';

} while ($x < 10);

?>

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a loop using PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why do we use Php?

PHP is an Open Source Scripting Language. We can create Web Pages and Web Applications using PHP.


How do you create a web mail script using PHP?

You can use phpMailer() Or, you can use mail() PHP function to send emails via PHP script.


How do you print 1 to 100 without using loop in php?

The best way to print the numbers 1 to 100 in PHP without using a loop is with the following code: echo implode("&lt;br&gt;", range(1,100)); You can replace the &lt;br&gt; with anything that you want to separate the numbers, such as dashes. I used a line-break in the example.


How do you make a blog using PHP and MySQL?

You can create blog in php. In fact, many blogs on the internet created using php. There are many readymade blogs which you can install on your own server. Or, if you wish, you can create your own blog application. Simply, blog is a dynamic website (users can add, delete, update content) and PHP was designed for creation of dynamic websites.


Why is PHP used?

PHP is used to create dynamic websites, this is a step up from HTML as it allows you to do much more than creating static websites. Using a language such as PHP also gives you access to using databases with your website such as MySQL.


Which loop is used in php?

while, do...while, for, foreach are used


How can you create a website without using a host like Shutterfly?

Maybe try mySQL or PHP?


How do you create a redirect webpage?

If you are using PHP you could use this code: (In the &lt;head&gt;) &lt;?php HEADER("Location: http://www.rasclerhys.com"); ?&gt; That should automatically take you to "www.rasclerhys.com"


How do you create a DIV type file using PHP?

A file with the DIV file extension is a DivX Movie file, it cannot be created with PHP. PHP is a web programming language for web site building.


How does you create a delete button in PHP using Dreamweaver?

That question doesn't make much sense...delete for what?


How do you install crystal reports for php?

how to create report in php


How do you make a login using PHP?

Create an HTML form with METHOD="post" and ACTION="login2.php". In login2.php check if the entered username and password are correct. You can get the username with $_POST['name_of_username_input']. The same goes for the password.