I have the following code that creates a revision timetable in the form of a multidimensional array. Each section represents a day and each hour a timeslot to revise in. Im trying to convert this multidimensional array into a table in mysql so that the timetable is user friendly and can be saved and so on. Here is the code used to generate the timetables and furthermore the the timetable generated.
<?php
if(!isset($_POST['subjects'])) {
header('Location: index.php');
}
define('DAY_LENGTH', 12);
$timetable = [];
foreach ($_POST as $subject => $n) { // add in the required amount of subjects
$timetable = array_merge($timetable, array_fill(0, $n, $subject));
}
$timetable = array_merge($timetable, array_fill(0, DAY_LENGTH * 7 - count($timetable), '')); // fill the array with empty values
shuffle($timetable); // shuffle the set
$timetable = array_chunk($timetable, DAY_LENGTH); // split it into 7 days
echo '<pre>';
var_dump($timetable);
echo '</pre>';
This is the array structure, it goes on for 7 sub arrays but i have only shown the first 2 to save time. Each sub array represents a day of the week ie [0] would be monday and each array within that is the time of the day followed by a subject i.e [8] = 8pm and physics
array(7) {
[0]=>
array(12) {
[0]=>
string(0) ""
[1]=>
string(9) "Computing"
[2]=>
string(7) "Physics"
[3]=>
string(7) "Physics"
[4]=>
string(7) "Physics"
[5]=>
string(5) "Maths"
[6]=>
string(7) "Physics"
[7]=>
string(7) "Physics"
[8]=>
string(7) "Physics"
[9]=>
string(7) "Physics"
[10]=>
string(7) "Physics"
[11]=>
string(7) "Physics"
}
[1]=>
array(12) {
[0]=>
string(7) "Physics"
[1]=>
string(9) "Computing"
[2]=>
string(7) "Physics"
[3]=>
string(7) "Physics"
[4]=>
string(7) "Physics"
[5]=>
string(7) "Physics"
[6]=>
string(5) "Maths"
[7]=>
string(7) "Physics"
[8]=>
string(7) "Physics"
[9]=>
string(7) "Physics"
[10]=>
string(7) "Physics"
[11]=>
string(5) "Maths"
}