Is it acceptable to output HTML using echo within PHP code?

It is acceptable to output HTML using echo within PHP code, but it is recommended to separate the HTML from the PHP logic for better readability and maintainability. One way to achieve this is by using PHP's alternative syntax for control structures, like foreach and if statements, to minimize the amount of HTML within echo statements.

<?php
// Example of separating HTML from PHP logic
$items = ['Apple', 'Banana', 'Orange'];

foreach ($items as $item) :
?>
    <div><?php echo $item; ?></div>
<?php
endforeach;
?>