我在something.php上为特色事件编写此代码
$day_start = date("j", mktime(0,0,0,$event_start_month, $event_start_day, $event_start_year));
$day_end = date("j", mktime(0,0,0, $event_end_month, $event_end_day, $event_end_year));
if (($day_start == $day_end)) {
$same_day = true;
}
<?php if ($same_day == false) { ?>
<span class="value value-date"> - <?php echo $day_end; ?></span>
当我回应这个
<?php if ($same_day == false) { ?>
<span class="value value-date"> - <?php echo $day_end; ?></span>
发生错误
Error Processing Feed: Undefined variable: same_day at something.php
答案 0 :(得分:0)
您应该始终为$same_day
分配内容以避免此警告。像这样:
if (($day_start == $day_end)) {
$same_day = true;
} else{
$same_day =false; // <-- This is the new part.
}
...
if ($same_day == false) {
否则只是一个通知。但更清洁,以妥善处理它
或者更简单的是不引入新变量。仅在第二个中使用($day_start == $day_end)
,并完全省略第一个。
答案 1 :(得分:0)
使用它来避免错误
$same_day = false;
if (($day_start == $day_end)) {
$same_day = true;
}
......
<?php if ($same_day == false) { ?>
<?php echo $day_end; ?>