PHP showing output of foreach to screen, for each item?

Salmane S

New member
this was suggested but it doesnt work. can anyone help please??
the output is given at once when the script finishes executing
ps I am runinng this script locally on MAMP Pro.
if (ob_get_level() == 0) ob_start();

$test = Array('one','two','three','four');
foreach ($test as $key=>$val)
{
echo $test;
ob_flush();
flush();
}

ob_end_flush();

thank you for ur help
 
you are using the foreach for the $test variable array. The value of the iteration is held in $val, so instead of "echo $test" you would want "echo $val" to print the value for the current iteration through the array.
 
Back
Top