Syntax

PHP For Loop Syntax

In PHP, for loop: loops a set number of times — for ($i = 0; $i < 10; $i++) { ... }

Quick Answer

Syntax
for ($i = 0; $i < 10; $i++) { ... }
PHPSyntax

For Loop

Code example
for ($i = 0; $i < 10; $i++) { ... }

Loops a set number of times.

Learn More

How to for loop in PHP

  1. Open your PHP file or editor.
  2. Copy the example, then replace its sample names and values for your code.

PHP For Loop Syntax

Use for ($i = 0; $i < 10; $i++) { ... }.

Related Syntax References

Frequently asked questions

What is the PHP syntax for for loop?

Use this pattern: for ($i = 0; $i < 10; $i++) { ... }

Can I copy this PHP code example?

Yes. Use Copy code and adapt the example to your program.

Is this PHP syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify