Hi,
I have this code which works just fine
function show_aval($place) {
echo $place;
}
ob_start();
show_aval(london);
$show_aval = ob_get_contents();
ob_clean();
ob_start();
show_aval(york);
$show_aval2 = ob_get_contents();
ob_clean();
ob_start();
show_aval(liverpool);
$show_aval3 = ob_get_contents();
ob_clean();
but I want to simplify this code like this:
$avalrooms = [];
$cities = ["london", "york", "liverpool"];
foreach ($cities as $city) {
ob_start();
show_aval($city);
$avalrooms[$city] = ob_get_contents();
ob_clean;
}
however, this seems to nullify ob_get_contents
because the function is being executed right away as show_aval($city);
is stated.
Why is this happening?
Thank you.