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!