1. Foreach Loop
a) Foreach loop fully depend array because you have an array , without array it's not worked.
b) foreach Loop working at the end of array.
c) Foreach is great for iterating through arrays that use keys and values.
Eg :Syntax is following.
$arr = array("Gourav","amit","Manoj","sonu","Rana","radhika "); // to define an array
foreach($array as $name ){
echo "Company Employe Name is ".$name.".";
}
Result as following.
Company Employe Name is Gourav.
Company Employe Name is amit.
Company Employe Name is Manoj.
Company Employe Name is sonu.
Company Employe Name is Rana.
Company Employe Name is radhika.
2. For Loop
a) For loop used according to condition.
b) Loop working at the end of given condition.
c) for loop is general purpose counter-based loop
Eg : Syntax is following.
$arr = array("Gourav","amit","Manoj","sonu","Rana","radhika "); // to define an array
for($i=0;$i<6;$i++){
echo " Company Employe Name is ".$arr[$i]."
" ;
}
Result as following.
Company Employe Name is Gourav
Company Employe Name is amit
Company Employe Name is Manoj
Company Employe Name is sonu
Company Employe Name is Rana
Company Employe Name is radhika