I'm trying to add a foreach to an array in php(it's part of a templating-language)
array('key' => 'some value' .
foreach ($contents as $content) {
echo '<li>';
echo $content['message'];
echo '</li>';
}; .
'more data',
)
This is the error: Parse error: syntax error, unexpected T_FOREACH in /home/zenconomy/deploy/trunk.zenconomy.se/webroot/zenconomy/controllers/public/om.php on line 62
You can't "put a foreach-loop into an array". Your best bet would be to first make the value, then put it into the array.
$value = '';
foreach($contents as $content) {
$value .= '<li>' . $content['message'] . '</li>';
}
$array = array('key' => 'some value ' . $value . ' more data');