How can you reset a result set in PHP to use it multiple times?

When working with a result set in PHP, it is not possible to reset it back to the beginning once it has been iterated through. To use the result set multiple times, you can store the data in an array and then iterate through the array as many times as needed.

// Fetch data from the database and store it in an array
$result = mysqli_query($conn, "SELECT * FROM table");
$data = [];
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}

// Iterate through the array multiple times
foreach ($data as $row) {
    // Process data
}