// For Loop
for loop use 3 parameters( under the first brackets, that can be assigned values).
// for ('initialization', 'Condition ', 'increment / decrement' );
for('$i=0',i<=5'','$i++',){
echo $i.'</br>';
}
// While Loop
$i = 1;
while( $i < 10){
echo $i.'</br>';
$i++;
}
// Do while
$i = 1;
do{
echo $i ;
$i++;
}
While($i < 10);
// foreach($variable as $key=> $value)
$i=['a',1,2];
foreach($i as $value){
echo $value ;
}
// To count Data. We use count function in php
$cars = array("Volvo","BMW","Toyota");
echo count( $cars );
// Recursive Count in php
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . count($cars)."<br>";
echo "Recursive count: " . count($cars,1);
//
0 Comments