How can you efficiently store query results in an array for later use in PHP?
When querying a database in PHP, you may want to store the results in an array for later use. To efficiently store query results in an array, you can loop through the results and push each row into an array. This allows you to easily access and manipulate the data later on in your code.
// Assuming $conn is your database connection and $query is your SQL query
$result = $conn->query($query);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
// Now $data contains all the query results in an array for later use
}