When creating reports with PHP, what are the best practices for handling data retrieval and presentation?

When creating reports with PHP, it is best practice to separate data retrieval and presentation logic. This can be achieved by using functions or classes to handle data retrieval from the database and then passing the retrieved data to the presentation layer for formatting and display. By following this approach, the code becomes more modular, easier to maintain, and promotes code reusability.

// Data retrieval function
function getDataFromDatabase() {
    // Code to retrieve data from the database
    return $data;
}

// Presentation logic
$data = getDataFromDatabase();

// Display data in report
foreach ($data as $row) {
    echo $row['column1'] . ' - ' . $row['column2'] . '<br>';
}