php for loop
<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
4
8
for($i = 0; $i <=10; $i++){
echo "The index is $i";
}
Thank you!
8
0
0
0
<?php
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
Thank you!
0
0
3
1
var listItem = [
{name: 'myName1', gender: 'male'},
{name: 'myName2', gender: 'female'},
{name: 'myName3', gender: 'male'},
{name: 'myName4', gender: 'female'},
]
for (const iterator of listItem) {
console.log(iterator.name+ ' and '+ iterator.gender);
}
Thank you!
1
0
4.25
3
<?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++);
?>
Thank you!
3
0
4
2
/*
For loop in php
*/
<?php
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
?>
Thank you!
2
0
Are there any code examples left?
New code examples in category PHP