How can the code snippet be modified to display the frequency of each dice roll outcome in a more structured manner?

The code snippet can be modified to display the frequency of each dice roll outcome in a more structured manner by using an associative array to store the frequencies of each outcome. This way, the results can be easily displayed in a structured format showing the outcome and its corresponding frequency.

<?php
// Simulate rolling a dice 100 times
$rolls = [];
for ($i = 0; $i < 100; $i++) {
    $roll = rand(1, 6);
    $rolls[] = $roll;
}

// Count the frequency of each dice roll outcome
$freq = [];
foreach ($rolls as $roll) {
    if (array_key_exists($roll, $freq)) {
        $freq[$roll]++;
    } else {
        $freq[$roll] = 1;
    }
}

// Display the frequency of each dice roll outcome in a structured manner
foreach ($freq as $outcome => $frequency) {
    echo "Outcome $outcome: $frequency times\n";
}
?>