Imran Omar Bukhsh Imran Omar Bukhsh - 1 year ago 85
PHP Question

Array Foreach Loop Prints Last Item Only

Why does the following only print one fruit?

$fruits = array('banana','apple','orange');
foreach($fruits as $fruit);
{
echo $fruit."<br>";
}


Output:

orange

Answer Source

Because you have an extra semicolon at the end of the foreach line. Remove it, and all should be well.