2016-01-28 68 views
-1

我是代碼編寫的外部,我有下面的代碼工作。如果條件顯示年,月,日

<?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.'; 
?> 

我該如何修改上面的代碼?

回答

0

如果我沒看錯你忘記關閉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.'; 
?> 
相關問題