PHP For Loops

PHP for loop is used when the specified condition is predefined. Syntax:
for (initialization; condition; increment/decrement ) {
code to be executed;
}
Example
<!DOCTYPE html>
<html>
<head>
<title>PHP Tutorial</title>
</head>
<body>
<?php
echo " Print counting using for loop"."<br>";
for($i=1;$i<=5;$i++){
echo $i."<br>";
}
?>
</body>
</html>
Output Print counting using for loop 1 2 3 4 5 PHP Nested For loop PHP Nested for loop is used inside the loop that is called nested for loop. Example:
<!DOCTYPE html>
<html>
<head>
<title>PHP Tutorial</title>
</head>
<body>
<?php
echo " Print prymid using Nested for loop"."<br>";
for($i=1;$i<=5;$i++){
            for($j=1;$j<=$i;$j++){
echo "*";
            }
            echo "<br>";
}
?>
</body>
</html>
Output Print pyramid using Nested for loop * ** *** **** *****

Related Topics

PHP array_map() Function

PHP array_map() Function The array_map() function  in PHP is used to return an array containing the results of applying the user-defined callback function over the elements of one or more arrays. Syntax array_map ( callable $callback , array $array1 [, array $... ] )  Parameter callable(required)- This parameter...

1 minute read.

PHP setlocale() Function

PHP setlocale() Function The setlocale() function in PHP sets locale information(language, monetary, time and, other information specific for a geographical area.) Syntax setlocale ( int $category , array $locale ) Parameter category(required)- This parameter specified a named constant specifying the category of the functions affected...

1 minute read.

PHP stristr() Function

PHP stristr() Function The stristr() function in PHP finds the first occurrence of a string and returns the matched substring. It is a case-insensitive function. Syntax stristr ( string $haystack , mixed $needle [, bool $before_needle ] ) Parameter haystack(required)- This parameter represents the input string. needle(required)- This parameter...

2 minutes read.

PHP var_export() Function

PHP var_export() Function The var_export() function in PHP is used to get the structured information for the specified variable. This function outputs or returns a parsable string representation of a variable. This function is similar to...

1 minute read.

PHP strstr() Function

PHP strstr() Function The strstr() function in PHP finds the first occurrence of a string. It returns part of the parameter haystack string starting from and including the first occurrence of needle to the end of the haystack parameter. This function is case-sensitive.  Syntax strstr ( string $haystack , mixed $needle [, bool $before_needle] )  Parameter  haystack(required)-...

2 minutes read.

PHP While Loop

PHP while loop is used to run the same block of code until a condition is met. It should be used if number of iteration it not known. Syntax: <?php while (condition){   //Code...

1 minute read.

PHP array_push() Function

PHP array_push() Function The array_push() function in PHP pushes one or more elements onto the end of the array. This function increases the length of the array by the number of variables pushed. Syntax array_push ( array &$array, mixed& value [, mixed $... ]...

1 minute read.

PHP Include Function

PHP Include( ) The PHP include() statement holds all the code/text that liesin the defined file and paste it into the file that uses the "include" statement. With the help of include...

3 minutes read.

PHP convert_uuencode() Function

PHP convert_uuencode() Function The convert_uuencode() function in PHP is used to encode a string and returns the uuencoded data. Syntax convert_uuencode ( string $data ) Parameter data(required)- This parameter represents the data to be encoded. Return This function returns the uuencoded data or FALSE on failure. Example 1 <?php //...

2 minutes read.

PHP array_walk_recursive() Function

PHP array_walk_recursive() Function The array_walk_recursive () function in PHP is used to apply a user-defined callback function recursively to each element of the array. This function returns a Boolean TRUE on success or FALSE on failure. Syntax array_walk_recursive ( array &$array , callable $callback [, mixed $userdata = NULL ] ) Parameter array(required)- This array represents the...

1 minute read.

WordPress Theme

Writing our WordPress Theme is relatively simple. Requirements: Before we begin, we need to know about the following set of requirements. We need to have full knowledge of WordPress setup, which is either...

2 minutes read.

PHP rtrim() Function

PHP rtrim() Function The rtrim() function in PHP is used to strip off the whitespace (or other characters) from the end of a string. If the second parameter is not specified, this function will strip are...

1 minute read.

PHP stripcslashes() Function

PHP stripcslashes() Function The stripcslashes() function in PHP returns a string with backslashes(\n, \r ..., octal and hexadecimal representation) stripped off. Syntax stripcslashes ( string $str )  Parameter str(required)- This parameter signifies the string to be unescaped. Return This function returns the unescaped string with backslashes stripped off. Example 1   ...

1 minute read.

PHP get_defined_vars() Function

PHP get_defined_vars() Function The get_defined_vars() function in PHP returns an array of all defined variables. It returns a multidimensional array containing a list of all defined variables. Syntax get_defined_vars ( void ) Parameter NA Return This function returns a multidimensional array containing a list...

1 minute read.

PHP implode() Function

PHP implode() Function The implode() function in PHP joins the specified array elements with a string. Syntax implode ( string $glue, array $pieces ) Parameter glue(optional)- It specifies what to put between the array elements. pieces(required)- This parameter represents...

1 minute read.

PHP metaphone() Function

PHP metaphone() Function The metaphone() function in PHP calculates the metaphone key (representing how a string sounds or pronounced) of a string. This function is used to text search and text matching or spelling...

1 minute read.

PHP array_change_key_case() Function

PHP array_change_key_case() Function The array_change_key_case() function in PHP is used to change the case of all keys present in the specified array. It returns an array with all keys in the specified array to lowercase or...

1 minute read.

PHP array_intersect_ukey() function

The array_intersect_ukey () function in PHP is used to compute the intersection of arrays with the help of a callable function on the keys for comparison. It returns an array containing all the...

1 minute read.

PHP fprintf() Function

PHP fprintf() Function The fprintf() function in PHP outputs a formatted string. This function operates as printf() but accepts an array of arguments, rather than a variable number of arguments. Syntax vprintf ( string $format , array $args ) Parameter format(required)- This parameter specifies the string and how to...

4 minutes read.

PHP str_repeat() Function

PHP str_repeat() Function The str_repeat() function in PHP repeats a string a specified number of times. Syntax str_repeat ( string $input , int $multiplier ) Parameter string(required)- This parameter signifies the string to be repeated. multiplier(required)- This parameter represents the number of times the string will be...

1 minute read.