Php

How to use for loop concept for php using find array values

Google+ Pinterest LinkedIn Tumblr

How to use for loop concept for php using find array values

for loop is used to initialize the code for how many times it should run.

syntax

for (initialization counter; total counter; increment counter) {
    code to be executed;
}

for example

<?php 
for ($x = 0; $x <= 5; $x++) {
    echo "The number is: $x <br>";
} 
?>

output

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

for loop php is used to count and auto increment the array values using loop.

What is Array?

An array is a variable, which can hold more than one value at a time.
php Array basic function defined as
array();

example

< ?php

$design = array('photoshop','flash','dreamviewer','html5');

echo $design[0]; //output is photoshop

echo $design[1]; //output is flash

?>

For more explanation about array

I'm Rajasekar - Web developer, Freelancer, Blogger and Owner of DeveloperDesks. From India lives in Bahrain. I love to do coding, Creating websites and trying different with code and designs. You Can Hire Me