Reputation: 4352
theres something i would like to try and has to do with including html on php, my code would be like this.
<?php
foreach($element as $data)
{
<div class="view">
echo $data;
</div>
}
?>
that would be just an example, of course it will give me error like not expected error.
i just would like to make a this function for each element in array thats in $element but it has to be repeated with the class on css style. how to do?
sorry im new at php
Upvotes: 0
Views: 55
Reputation: 2612
<?php
foreach($element as $data){
echo "<div class='view'>";
echo $data;
echo "</div>";
}
?>
OR:
<?php foreach($element as $data){?>
<div class='view'>
<?php echo $data; ?>
</div>
<?php } ?>
Upvotes: 0
Reputation: 4331
Try like this :
<?php foreach($element as $data){ ?>
<div class="view">
<?php echo $data; ?>
</div>
<?php } ?>
Upvotes: 0
Reputation: 165062
<?php foreach ($element as $data) : ?>
<div class="view">
<?= htmlspecialchars($data) ?>
</div>
<?php endforeach ?>
Upvotes: 4
Reputation: 1481
Two way is there
<?php foreach($element as $data) { ?>
<div class="view">
<?php echo $data; ?>
</div>
<?php } ?>
OR
<?php foreach($element as $data) {
echo '<div class="view">';
echo $data;
echo '</div>';
} ?>
Upvotes: 1