How can PHP arrays be properly structured to store and retrieve database query results?

When storing database query results in PHP arrays, you can structure the array to have each row of the query result as a sub-array within the main array. This allows for easy retrieval of individual rows or specific data points. To achieve this, you can use a loop to fetch each row from the query result and append it to the main array.

// Assume $queryResult contains the result of a database query

$databaseResults = array();

while ($row = mysqli_fetch_assoc($queryResult)) {
    $databaseResults[] = $row;
}

// Now $databaseResults is a structured array containing all the query results