I'm trying to take the values of an array and display it as a list. I've used a foreach to do this before but for some reason I can't figure out why it's not working this time around. In the code below, $output is the contents of an entire page generated through AJAX and is later echo'd out on the bottom of the script. Everything seems to be working except this one small section. I managed to get this exact same information to display on a separate static page (without the $output) so I'm not sure why it's not working here.
if(!empty($record['utilities'])) {
$output .= "<ul>";
foreach ($record['utilities'] as $eachUtility):
// $output .= "<li>" echo $eachUtility; "</li>";
$output .= "<li>" . $eachUtility . "</li>";
endforeach;
$output .= "</ul>";
// $output .= $record['utilities']; This works
}
Here's a working example of the same code that was hard coded on a separate page:
<?php if(!empty($record['utilities'])) { ?>
<ul>
<?php foreach ($record['utilities'] as $eachUtility): ?>
<?php echo ('<li>' . $eachUtility . '</li>'); ?>
<?php endforeach ?>
</ul>
<?php } ?>