what is php for code example

Example 1: for loop php

<?php
	$fruits = ["apple", "banana", "orange"];
	for($i=0;$i<count($fruits);$i++){
    echo "Index of ".$i."= ".$fruits[$i]."<br>";
    }
  ?>

Example 2: php for

<?php
/* example 1 */

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}

/* example 2 */

for ($i = 1; ; $i++) {
    if ($i > 10) {
        break;
    }
    echo $i;
}

/* example 3 */

$i = 1;
for (; ; ) {
    if ($i > 10) {
        break;
    }
    echo $i;
    $i++;
}

/* example 4 */

for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
?>

Example 3: what php can do

PHP can generate dynamic page content.
PHP can create, open, read, write, delete, and close files on the server.
PHP can collect form data.
PHP can send and receive cookies.
PHP can add, delete, modify data in your database.
PHP can be used to control user-access.
PHP can encrypt data and apply validation.
PHP used to send and receive E-Mails.
PHP can be used to integrate with other third party tools.
PHP can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

Example 4: for i php

<?php
  
  for ($i = 1; $i <= 10; $i++) {
    echo $i;
  }

Tags:

Php Example