for php
<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
for php
<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
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++);
?>
foreach loop array php
foreach (array as $value){
//code to be executed;
print("value : $value");
}
foreach (array as $key => $value){
//code to be executed;
print("key[$key] => $value");
}
foreach in php
$arr = array(
'key1' => 'val',
'key2' => 'another',
'another' => 'more stuff'
);
foreach ($arr as $key => $val){
//do stuff
}
//or alt syntax
foreach ($arr as $key => $val) :
//do stuff here as well
endforeach;
for php
<?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++;
}
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us