使用两个键从SQL创建多维数组

My SQL table is structured like this: class_id, class_name, day

I want to convert this into a multidimensional array structured as below

$days['day']['class_id']

My attempt so far is as follows:

while ($row = mysqli_fetch_assoc($result)) {
    $days[$row['day']] = $row;
}

This creates a second layer to the array based on the day, however I'm not sure how to develop that further to sort the rows based on class_id.

I then want to echo each row out based on the day using the id as the key using a foreach loop. This is what I have so far.

   foreach ($days['Monday'] as $id => $value) {

         echo "<div class='class'>";
         echo $value['class_name'];
         echo "</div>";

Any help would be massively helpful!

while ($row = mysqli_fetch_assoc($result)) {
    $days[$row['day']][$row['class_id']] = $row;
}

and then use it in foreach like you wrote.