What best practices should be followed when separating the counter logic from the display logic in PHP?

When separating the counter logic from the display logic in PHP, it is important to follow best practices such as using separate functions or classes for each type of logic, avoiding mixing the two in the same code block, and ensuring that the counter logic is properly encapsulated and reusable.

// Counter logic
function countItems($items) {
    return count($items);
}

// Display logic
function displayItems($items) {
    foreach ($items as $item) {
        echo $item . "<br>";
    }
}

// Example usage
$items = ['Apple', 'Banana', 'Orange'];
$count = countItems($items);
echo "Total items: $count <br>";
displayItems($items);