<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
/*
For loop in php
*/
<?php
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
?>
<?php
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
<?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++);
?>
for($i = 0; $i <=10; $i++){
echo "The index is $i";
}
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
<?php
$fruits = ["apple", "banana", "orange"];
for ($i = 0; $i < count($fruits); $i++) {
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
// or
$i = 0;
foreach ($fruits as $value) {
echo "Index of ".$i."= ".$value."<br>";
$i++;
}
?>
<?php
$variable = '' ;
for($counter=0;$counter<$limit;$counter++){
//code
}
?>
for($i = 1; $i > 10; $i++){
//show i value
echo "Your Number Is :$i";
}
for($i = 0;$i < count($users);$i++) {
if($users[$i]['user_id']==3){
$userName = $users[$i]['first_name'];
}
}
for($i=0; $i<sizeOf($temp); $i++)
{
}
for($i=0;$i<count($array);$i++){
}
Code Example |
---|
:: choose a random word from an array php |
Php :: |
:: wordpress get username |
:: redirect in codeigniter |
:: |
Php :: |
Php :: |
:: |
:: check if number is float in php |
:: |
:: |
:: |
Php :: |
:: |
Php :: flutter form set next input |
:: |
Php :: |
Php :: |
Php :: |
:: |
:: |
Php :: |
:: carbon set locale laravel |
:: |
Php :: group users on country vice in laravel |
:: |
:: |
Php :: |
:: |
Php :: |