How can SQL queries be used to populate an array in PHP?

To populate an array in PHP using SQL queries, you can establish a database connection, execute the SQL query to fetch the data, and then loop through the results to populate the array. You can use functions like `mysqli_query()` and `mysqli_fetch_assoc()` to achieve this.

// Establish a connection to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Execute SQL query to fetch data
$query = "SELECT column1, column2 FROM table";
$result = mysqli_query($connection, $query);

// Populate array with fetched data
$dataArray = array();
while ($row = mysqli_fetch_assoc($result)) {
    $dataArray[] = $row;
}

// Close the connection
mysqli_close($connection);

// Print the populated array
print_r($dataArray);