What is the purpose of using a loop in PHP code and how can it be implemented to display multiple items in a row?

Using a loop in PHP code allows us to iterate over a set of data or perform a task multiple times without having to write repetitive code. To display multiple items in a row, we can use a loop to iterate over an array of items and output each item within a specified HTML structure.

<?php
$items = array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5");

echo "<div>";
foreach($items as $item) {
    echo "<span>$item</span>";
}
echo "</div>";
?>