Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果条件显示年、月、日_Php_If Statement - Fatal编程技术网

Php 如果条件显示年、月、日

Php 如果条件显示年、月、日,php,if-statement,Php,If Statement,我是一名外行的代码编写人员,我有下面的代码正在工作 <?php $datetime1 = new DateTime("$date_of_dissolution"); $datetime2 = new DateTime("$date_of_incorp"); $difference = $datetime1->diff($datetime2); echo 'And the company is running: '.$difference->y.' years, '.$diffe

我是一名外行的代码编写人员,我有下面的代码正在工作

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$difference = $datetime1->diff($datetime2);
echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>

但是我想再添加一个条件,但是下面的代码不起作用

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$datetime3 = new DateTime("$date_commenced_dormancy");
$datetime4 = date("Y-m-d");

if ($active_status ==('Live but Commenced Dormancy')) {
$difference = $datetime3->diff($datetime2);
} elseif  ($active_status ==('Dissolved')) {
$difference = $datetime1->diff($datetime2);
} else {
$difference = $datetime4->diff($datetime2);

echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>


我应该如何修改上述代码?

如果我没有错,请忘记关闭else语句的大括号

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$datetime3 = new DateTime("$date_commenced_dormancy");
$datetime4 = date("Y-m-d");

if ($active_status ==('Live but Commenced Dormancy')) {
$difference = $datetime3->diff($datetime2);
} elseif  ($active_status ==('Dissolved')) {
$difference = $datetime1->diff($datetime2);
} else {
$difference = $datetime4->diff($datetime2);
}

echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>