How can utilizing session arrays in PHP help manage and store data more efficiently when dealing with multiple queries?

When dealing with multiple queries in PHP, utilizing session arrays can help manage and store data more efficiently by persisting the data across multiple page loads. This allows you to store information such as query results or user input in a structured format that can be easily accessed and manipulated throughout the user's session.

// Start the session
session_start();

// Store query results in a session array
$_SESSION['query_results'] = array();

// Add query results to the session array
$query_result = // Perform query
$_SESSION['query_results'][] = $query_result;

// Access and manipulate the stored data
foreach ($_SESSION['query_results'] as $result) {
    // Process query results
}