How can the array_push() function be utilized in PHP to efficiently build arrays from database query results?

When retrieving data from a database query in PHP, we often need to build an array from the results. The array_push() function can be used to efficiently add elements to an existing array. By looping through the query results and using array_push() to add each row to the array, we can quickly build an array from the database query results.

// Assume $query_results contains the results of a database query

$data_array = array();

while($row = $query_results->fetch_assoc()) {
    array_push($data_array, $row);
}

// $data_array now contains all the rows from the database query results