我目前正在設計一個程序,爲學生創建修訂時間表。我試圖創建一個函數,通過一個二維數組,並將主題插入到該數組中的隨機位置,即在星期一的第12號槽中的數學運算,然後移動到第二天。我將兩個主題分配給每個小時星期設置爲前一頁的變量我只需要幫助選擇主數組中的每個數組。這裏是我的2darray,牢記香港專業教育學院只包括第3個陣列,以節省空間甚至儘管有7如何使用foreach將值添加到數組中的每個數組中?
$Timetable = array(
"0" => array // 0 = Monday 6= Sunday
// 0 - 24 = horus
(
"0" => "",
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => "",
"9" => "",
"10" => "",
"11" => "",
"12" => "",
"13" => "",
"14" => "",
"15" => "",
"16" => "",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "",
"22" => "",
"23" => "",
"24" => "",
),
"1" => array
(
"0" => "",
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => "",
"9" => "",
"10" => "",
"11" => "",
"12" => "",
"13" => "",
"14" => "",
"15" => "",
"16" => "",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "",
"22" => "",
"23" => "",
"24" => "",
),
"2" => array
(
"0" => "",
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => "",
"9" => "",
"10" => "",
"11" => "",
"12" => "",
"13" => "",
"14" => "",
"15" => "",
"16" => "",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "",
"22" => "",
"23" => "",
"24" => "",
),
);
預期的結果,就是如果用戶填入值,用戶放,例如表已經進入數學4小時英語6和生物2的數組可能看起來像這樣。
'$'Timetable = array(
"0" => array // 0 = Monday 6= Sunday
// 0 - 24 = horus
(
"0" => "",
"1" => "",
"2" => "",
"3" => "english",
"4" => "",
"5" => "",
"6" => "",
"7" => "maths",
"8" => "",
"9" => "biology",
"10" => "",
"11" => "english",
"12" => "",
"13" => "",
"14" => "",
"15" => "",
"16" => "",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "",
"22" => "maths",
"23" => "",
"24" => "",
),
"1" => array
(
"0" => "",
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => "",
"9" => "english",
"10" => "",
"11" => "maths",
"12" => "",
"13" => "",
"14" => "",
"15" => "",
"16" => "english",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "english",
"22" => "",
"23" => "",
"24" => "",
),
"2" => array
(
"0" => "",
"1" => "",
"2" => "",
"3" => "",
"4" => "",
"5" => "",
"6" => "",
"7" => "",
"8" => "",
"9" => "",
"10" => "",
"11" => "",
"12" => "",
"13" => "biology",
"14" => "",
"15" => "english",
"16" => "",
"17" => "",
"18" => "",
"19" => "",
"20" => "",
"21" => "",
"22" => "",
"23" => "maths",
"24" => "",
),
);
你能提供預期的結果嗎?因爲它不完全清楚你想在這裏實現什麼。 – BVengerov
如果您的子陣列從0到24,您是否有24天的25個條目?你不應該放鬆「24」,或者你有兩個「午夜」條目的理由嗎? –
@BozidarSikanjic它應該從0-23你是正確的謝謝 –