How can PHP arrays be effectively used to store and manipulate data retrieved from a database in a while loop?

When retrieving data from a database in a while loop, PHP arrays can be effectively used to store and manipulate this data. Within the while loop, each row fetched from the database can be stored in an array, allowing for easy access and manipulation of the data. By using PHP arrays, you can efficiently handle and process the retrieved database information.

// Example of using PHP arrays to store and manipulate data retrieved from a database in a while loop

// Connect to database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query to fetch data
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Initialize an empty array to store data
$dataArray = array();

// Fetch data in a while loop and store in array
while ($row = mysqli_fetch_assoc($result)) {
    $dataArray[] = $row;
}

// Manipulate data stored in the array
foreach ($dataArray as $data) {
    echo $data['column_name'];
}

// Close database connection
mysqli_close($connection);