What is the best practice for storing and accessing results of multiple SELECT queries in PHP?

When storing and accessing results of multiple SELECT queries in PHP, it is best to use arrays to hold the data from each query. You can create an associative array where the keys represent the query names and the values represent the result sets. This allows you to easily access the data later on in your code.

// Store results of multiple SELECT queries in an associative array
$results = [];

// Execute and store results of first SELECT query
$query1 = "SELECT * FROM table1";
$result1 = mysqli_query($connection, $query1);
$results['query1'] = mysqli_fetch_all($result1, MYSQLI_ASSOC);

// Execute and store results of second SELECT query
$query2 = "SELECT * FROM table2";
$result2 = mysqli_query($connection, $query2);
$results['query2'] = mysqli_fetch_all($result2, MYSQLI_ASSOC);

// Access data from first SELECT query
foreach ($results['query1'] as $row) {
    echo $row['column_name'] . "<br>";
}

// Access data from second SELECT query
foreach ($results['query2'] as $row) {
    echo $row['column_name'] . "<br>";
}