0

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

1 Answer 1

4

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.