What is PHP?

  • The PHP Hypertext Preprocessor (PHP) is a server scripting language, used for making dynamic web pages.
  • PHP is an open source software and it is free to download and use.
  • PHP supports a wide range of databases like MySQL, Oracle, Sybase, Solid, PostgreSQL etc.

What is For loop?

  • For loop is a programming language conditional iterative statement.
  • Which is used to check for certain conditions and then repeatedly execute a block of code as long as those conditions are met.

For loop is a control Statement.

Syntax

for (init counter; test counter; increment counter) {code to be executed;}
PHP

In for loop there are 3 section.

  • The init counter is Used for Intialize Because it is Executed only once.
  • The test counter Check the Condition. Here we Write Expression which you can be Executed Multiple Times.
  • The increment counter is Used for Increasing or Decreasing the value of a variable or can Write any Expression. It is also Executed Several Times.

Example For Loop

<?phpfor($a=1;$a<=10;$a++)echo "$a <br>";?>
PHP

PHP foreach loop

  • foreach loop is a special type of control statement which is used for array .
  • it access all the elements in an array .

Syntax

foreach ($array as $value) {code to be executed;}
PHP

Example Foreach

<?php$data=array(1,2,3,4,5);foreach($data as $element){echo "$element";}?>
PHP