Imran Omar Bukhsh Imran Omar Bukhsh - 1 year ago 100
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download