在 laravel 中添加两个整数
add two integers in laravel
基本上我想要的是将两个数字相加并求和。
这是我的代码:
if (isset($this->date_filed) && !empty($this->date_filed) && !empty($this->date_forwarded_to_cmt_contractor)) {
$date_forwarded_to_cmt_contractor = Carbon::createFromFormat('Y-m-d', $this->date_forwarded_to_cmt_contractor);
$date_filed = Carbon::createFromFormat('Y-m-d', $this->date_filed);
$interval = $date_filed->diff($date_forwarded_to_cmt_contractor);
$this->cst_to_cmt = $interval->format('%a' . ' ' . 'Days');
if ($this->status == 'RECTI03') {
$now = Carbon::now();
$date_forwarded_to_cmt_contractor = Carbon::createFromFormat('Y-m-d', $this->date_forwarded_to_cmt_contractor);;
$interval = $date_forwarded_to_cmt_contractor->diff($now);
$this->cmt_to_current_date = $interval->format('%a' . ' ' . 'Days');
}
$this->date_filed_to_current_date = $this->cst_to_cmt + $this->cmt_to_current_date;
}
这是我尝试添加它们的部分。
$this->date_filed_to_current_date = $this->cst_to_cmt + $this->cmt_to_current_date;
但是我收到了这个错误。为什么 ? :/
"A non well formed numeric value encountered"
将类型转换为 integer
怎么样?
$this->date_filed_to_current_date = (int)$this->cst_to_cmt + (int)$this->cmt_to_current_date;
如果数字中包含逗号或任何其他不需要的非数字字符,例如字符串中的 ,
或 -
,那么您将收到通知 A遇到格式不正确的数值 所以最好在添加操作之前将其转换为整数类型。
工作演示: https://3v4l.org/DAcWa
基本上我想要的是将两个数字相加并求和。
这是我的代码:
if (isset($this->date_filed) && !empty($this->date_filed) && !empty($this->date_forwarded_to_cmt_contractor)) {
$date_forwarded_to_cmt_contractor = Carbon::createFromFormat('Y-m-d', $this->date_forwarded_to_cmt_contractor);
$date_filed = Carbon::createFromFormat('Y-m-d', $this->date_filed);
$interval = $date_filed->diff($date_forwarded_to_cmt_contractor);
$this->cst_to_cmt = $interval->format('%a' . ' ' . 'Days');
if ($this->status == 'RECTI03') {
$now = Carbon::now();
$date_forwarded_to_cmt_contractor = Carbon::createFromFormat('Y-m-d', $this->date_forwarded_to_cmt_contractor);;
$interval = $date_forwarded_to_cmt_contractor->diff($now);
$this->cmt_to_current_date = $interval->format('%a' . ' ' . 'Days');
}
$this->date_filed_to_current_date = $this->cst_to_cmt + $this->cmt_to_current_date;
}
这是我尝试添加它们的部分。
$this->date_filed_to_current_date = $this->cst_to_cmt + $this->cmt_to_current_date;
但是我收到了这个错误。为什么 ? :/
"A non well formed numeric value encountered"
将类型转换为 integer
怎么样?
$this->date_filed_to_current_date = (int)$this->cst_to_cmt + (int)$this->cmt_to_current_date;
如果数字中包含逗号或任何其他不需要的非数字字符,例如字符串中的 ,
或 -
,那么您将收到通知 A遇到格式不正确的数值 所以最好在添加操作之前将其转换为整数类型。
工作演示: https://3v4l.org/DAcWa