初学者:如果其他约会



我是php的绝对初学者,我只是想做一个简单的if-else语句。请看一下:

<?php  
        $currentDate  = echo date("Y");
        $startup = '2013';
        if ($startup = $currentDate) {
      ?>
        &copy; 2013 Blue Box 22
      <?php } else { ?>
        &copy; 2013 - <?php echo date("Y"); ?> Blue Box 22
      <?php } ?>

正如你可能读到的,我只是在检查当前年份是否等于启动年份,然后让它相应地显示。我想我的语法有问题,因为我页面的那部分没有呈现出来。

谢谢你的帮助!

代替:

if ($startup = $currentDate) { 

应该是

if ($startup == $currentDate) { 

此外,不使用

$currentDate  = echo date("Y");

尝试:

$currentDate  = date("Y");

您已经在if语句中分配了变量,而不是进行比较。与==运算符进行了比较。

if ($startup == $currentDate) {
}

这意味着如果(启动等于当前日期,则执行此操作)

<?php  
        $currentDate  = date("Y");//echo removed, never use while comparison
        $startup = '2013';
        if ($startup == $currentDate) {// comparison is done by ==, = make assignment
      ?>
        &copy; 2013 Blue Box 22
      <?php } else { ?>
        &copy; 2013 - <?php echo date("Y"); ?> Blue Box 22
      <?php } ?>

这意味着分配"="这意味着比较"=="

这将有助于您编写代码。:)

最新更新