我只想在一周的某些日子里显示一些HTML。我想我很亲密,但不能让这个工作。谢谢你的帮助。
<?php
$dayofweek = date('l');
$daystoshow = array('Thursday','Sunday','Wednesday');
if ($dayofweek == $daystoshow) {
echo "show this";
}
?>
答案 0 :(得分:3)
使用in_array()
检查数组中是否有值:
if (in_array($dayofweek, $daystoshow)) {
答案 1 :(得分:0)
奥莱特:
让我们使用PHP
日期函数
您是否只想在特定月份展示它?
$date = date("m");
if ($date == "01") { // only on january
//output
}
您是否只想在特定日期展示它?
$date = date("d");
if ($date == "01") { //Only on the first of the month
//output
}
您是否只想在特定日期展示它?
$days = array("01","11","28");
$date = date("d");
if (in_array($date,$days)) { //Only 01,11,28
//output
}
您是否只想在一周的特定日子里展示它?
$days = array("Thursday","Sunday","Wednesday");;
$date = date("l");
if (in_array($date,$days)) {
//output
}
您是否只想在特定年份展示它?
$date = date("Y");
if ($date == "2014") { //Only on 2014
//output
}