好的,所以這是我的第一個問題,所以請顯示一些憐憫。我正在開發一個Web應用程序來增加我在PHP編程方面的知識,但是我遇到了一個問題。PHP - 延長時鐘顯示23-24-25而不是23-00-01
我的webapp是由時間驅動的。因此,例如當時鍾是17:00時,它顯示存儲在多維數組中的一條信息。而當時鍾是18:30時,它會顯示陣列中的其他信息。問題是,我有一些信息需要在例如25:12時顯示,而不改變當前日期。
所以問題: 你可以讓時鐘顯示時間爲24:00-25:00-26:00,而不是00:00-01:00-02:00,雖然仍是上同一天?比如說,時鐘在26:00之後,星期一將從星期一變爲星期二?這是一個多維數組的例子。它可以一直工作到23:59,但時鐘當然只會上升到00:00,當然也會改變。那麼你能在PHP中「延長」這一天嗎?
例子:
//This is one of the arrays I´ve got. This one only works on Monday-Friday.
//It´s called "H103.php
$tur = array
(
array("RYEV", "6:26", "Møt", 1),
array("RYEV", "6:36", "Uttak", 1),
array("RYE2", "6:39+", "N", 1),
array("FRS2", "7:29", "D", 1),
array("FRS1", "7:43", "N", 1),
array("BKR1", "8:47+", "N", 1),
array("FRS2", "9:44", "D", 1),
array("FRS1", "9:58", "N", 1),
array("BKR1", "11:02+", "N", 1),
array("FRS2", "11:59", "D", 1),
array("FRS1", "12:13", "N", 1),
array("BKR1", "13:17+", "N", 1),
array("FRS1", "14:14", "D", 1),
array("FRS1", "14:28", "N", 1),
array("BKR1", "15:32+", "N", 1),
array("FRS2", "16:29", "D", 1),
array("FRS1", "16:43", "N", 1),
array("BKR1", "17:47+", "N", 1),
array("FRS2", "18:44", "D", 1),
array("FRS1", "18:58", "N", 1),
array("HFY2", "20:00+", "N", 1),
array("FRS2", "20:44", "D", 1),
array("FRS1", "20:58", "N", 1),
array("HFY2", "22:00+", "N", 1),
array("FRS2", "22:44", "D", 1),
array("FRS1", "22:58", "N", 1),
array("HFY2", "24:00+", "N", 1),
array("FRS2", "24:47", "D", 1),
array("MAJ3", "25:15", "D", 1),
array("AVL2", "25:35", "D", 1),
array("SPO6", "25:38", "Inn", 1),
);
//Define time into variable and counts array in total.
$klokkeT = date("H:i");
$antT = count($tur);
$u = 0;
//Finding out which line from the array to take based on time,
//and the storing it in a variable to show it on the website.
if ($_SESSION["kjoreLinje"] == 1 && $_SESSION["retning"] == "O"){
for ($m = 0; $m < $antT; $m++) {
$u++;
if ($u < $antT) {
if ($klokkeT >= $tur[$m][1] AND $klokkeT <= $tur[$u][1]) {
$turF1 = $tur[$m][0]; $turF2 = $tur[$m][1]; $turF3 = $tur[$m][2];
$turF4 = $tur[$m][3]; $turN1 = $tur[$u][0]; $turN2 = $tur[$u][1];
$turN3 = $tur[$u][2]; $turN4 = $tur[$u][3];
} } }
//System choosing which file to take based on what day it is
$weekdays = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
//weekdays
for ($i = 0; $i < 5; $i++){
if ($_SESSION["day"] == $weekdays[$i]) {
if ($_SESSION["togNr"] == 103) {
include_once 'Kjoretavler/Hverdag/Linje1/H103.php'; }
//Saturday
if ($_SESSION["dag"] == "Saturday") {
if ($_SESSION["togNr"] == 103) {
include_once 'Kjoretavler/Lordag/Linje1/L103.php'; }
//Sunday
if ($_SESSION["dag"] == "Sunday") {
if ($_SESSION["togNr"] == 103) {
include_once 'Kjoretavler/Sondag/Linje1/S103.php'; }
爲什麼你必須堅持到某一天?時差是不夠的?您可以分別解析24:00+小時以解決該問題。 –
你也應該給我們展示一些php代碼... –
讓我試着解釋一下。我有很多PHP文件,數據存儲在多維數組中。某些文件僅在週一活動,而其他一些文件僅在週六活動。這就是爲什麼我必須「延長」一天到星期一 - 26:32,因爲存儲在多維數組中的不同時間戳一直到26:30。 只更改時間對我的實例不起作用,因爲file.php僅在星期一活動,而file2.php僅在星期六活動(僅舉例)。 – Marcus