致命错误:在整数上调用成员函数 format()


Fatal error: Call to a member function format() on integer

    $total = $_POST['total'];
$myselect = $_POST['myselect'];
$t = '2';
// function date
$date_go = "$rn_gostart"; //กำหนดค้นวันที่เริ่ม
$date_end = "$rn_endstart"; //กำหนดค้นวันที่กลับ
$datetime1 = new DateTime($date_go);
$datetime2 = new DateTime($date_end);
$datetotal = $datetime1->diff($datetime2);
if ($datetotal = 0 ) {
$total = '1800';
}else {
 $total= $datetotal->format('%a') * 1800*$myselect;  //ผลการคำนวณ
}

问题是,如果我预订这样的一天:10.07.2559 * 07.10.2559 = 0,但如果它会预订 10/01/2559 * 11/07/2559。这是正常的

更改:

if ($datetotal = 0 )

自:

if ($datetotal == 0 )

您当前的代码将零分配给$datetotal,使您的代码在线上失败:

$total = $datetotal->format('%a') * 1800*$myselect;

格式%a不正确。它必须替换为有效的格式,具体取决于您要执行的操作。

如果我不使用,否则使用

$total = $_POST['total'];
$myselect = $_POST['myselect'];
// function date
$date_go = "$rn_gostart"; //กำหนดค้นวันที่เริ่ม
$date_end = "$rn_endstart"; //กำหนดค้นวันที่กลับ
$datetime1 = new DateTime($date_go);
$datetime2 = new DateTime($date_end);
$datetotal = $datetime1->diff($datetime2);
$total= $datetotal->format('%a') * 1800 * $myselect;

10.07.2559 * 08.10.2559 = 1800

但是 10.07.2559 * 07.10.2559 = 0