php foreach in heredoc

Solutions on MaxInterview for php foreach in heredoc by the best coders in the world

showing results for - "php foreach in heredoc"
Maëlle
01 Mar 2016
1$arr['John'] = 20;
2$arr['Peter'] = 30;
3
4$foreach = function ($array, $param) {
5	$result = '';
6	foreach ($array as $key => $value) {
7		$search = ["{key}", "{value}"];
8		$replace = [$key, $value];
9		$result .= str_replace($search, $replace, $param);
10	}
11
12	return $result;
13};
14
15echo <<<HTML
16	<ul>
17		{$foreach($arr, '<li>{key} is {value} years old</li>')}
18	<ul>
19HTML;