For loops a little faster, but consider the following:
$bar = array("cow"=>"moo", "cat"=>"meaw", "dog"=>"barf");
foreach($bar as $key => $value){
echo "The ".$key." goes ".$value.".<br>";
}
- With foreach, you get easier access to values as well as key values. This becomes easier and more obvious when using associative arrays.
- foreach is a little easier to read and maintain.
source
share