In terms of efficiency, is it better to retrieve information from a database again on a new page or pass it through an array from the previous page?

Retrieving information from a database again on a new page can be less efficient compared to passing it through an array from the previous page. This is because querying the database again incurs additional overhead in terms of processing time and resources. Passing the information through an array allows for quicker access to the data without the need for another database query.

// Previous page
$data = fetchDataFromDatabase();

// Store data in session array
$_SESSION['data'] = $data;

// New page
$data = $_SESSION['data'];

// Use the data as needed
foreach ($data as $row) {
    // Process each row
}