Imran Omar Bukhsh Imran Omar Bukhsh - 1 year ago 77
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>";



Answer Source

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