php foreach in heredoc
$arr['John'] = 20;
$arr['Peter'] = 30;
$foreach = function ($array, $param) {
$result = '';
foreach ($array as $key => $value) {
$search = ["{key}", "{value}"];
$replace = [$key, $value];
$result .= str_replace($search, $replace, $param);
}
return $result;
};
echo <<<HTML
<ul>
{$foreach($arr, '<li>{key} is {value} years old</li>')}
<ul>
HTML;