好的,这是我在这里的第一个问题,所以请表示一些怜悯。我正在开发一个Web应用程序来增加我对PHP编程的了解,但是我遇到了一个问题。
我的网络应用程序是由时间驱动的。因此,当例如时钟是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'; }
答案 0 :(得分:0)
我得到了@Andreas的答案来处理一些修改。似乎他已经取消了他的答案,所以我不能给他应得的功劳。再次感谢,对不好的解释感到抱歉。我已经学到了很多东西。编辑:适合我的代码。
if (date("G") <= 3) {
$day = Date("l", strtotime("yesterday"));
$time = 24 + intval(date("G")) . date(":i");
} else {
$day = date("l");
$time = date("G:i");
}
echo $day . " \n";
echo $time;