I have tried many approaches to get this right, including all types of quoting, etc. I will give you my current code before explaining the situation.
function show_msgs($msgs)
{
foreach($msgs as $msg) {
echo '<div class="msg">' . $msg . '</div>' . "
";
}
}
function generate_msgBox()
{
global $array;
$stackoverflow =
<<<EOT
<div class="container">
<div class="msgBox">
%s
</div>
</div>
EOT;
$stackoverflow = sprintf($stackoverflow, show_msgs($array));
echo $stackoverflow;
}
generate_msgBox function currently outputs this when called:
<div class="msg">First message!</div>
<div class="msg">Seconds message!</div>
<div class="container">
<div class="alertBox">
</div>
</div>
However I need it to output this:
<div class="container">
<div class="alertBox">
<div class="msg">First message!</div>
<div class="msg">Seconds message!</div>
</div>
</div>
I tried putting function directly inside echo that is enclosed by normal quotes and I got the same result.
How do I fix this?