1

我将使用保修日、月和年创建保修日期。一次输入一条记录时,此功能正常工作。但是我必须以相同的形式为不同的项目输入几个保修天。

for($value = 0; $value < count(array_filter($part_name1)); $value++){               
    if(!empty($year1[$value])||!empty($month1[$value])||!empty($days1[$value])){
        $warranty_date   = $this->purchase_date;
        if(!empty($days1[$value])){
            $warranty = strtotime($this->warranty_date);
            $warranty = strtotime("+".$this->days." day", $warranty);
            $warranty = date('Y-m-d', $warranty);
            $warranty_date = $warranty;
        }

        if(!empty($month1[$value])){
            $warranty        = strtotime($this->warranty_date);
            $warranty        = strtotime("+".$this->month." month", $warranty);
            $warranty        = date('Y-m-d', $warranty);
            $warranty_date   = $warranty;
        }

        if(!empty($this->year)){
            $warranty        = strtotime($this->warranty_date);
            $warranty        = strtotime("+".$this->year." year", $warranty);
            $warranty        = date('Y-m-d', $warranty);
            $warranty_date   = $warranty;
        }


    }
}

请帮我找出这段代码的错误。

此功能基于购买日期。
当我输入几条记录时,第一条保修日期显示1970-01-01,第二条记录保修日期正确,其余显示1970-01-01

4

1 回答 1

2
you missed last curly brace 

<?php 


for($value = 0; $value < count(array_filter($part_name1)); $value++){               
            if(!empty($year1[$value])||!empty($month1[$value])||!empty($days1[$value])){
                $warranty_date   = $this->purchase_date;
                if(!empty($days1[$value])){
                    $warranty = strtotime($this->warranty_date);
                    $warranty = strtotime("+".$this->days." day", $warranty);
                    $warranty = date('Y-m-d', $warranty);
                    $warranty_date = $warranty;
                }

                if(!empty($month1[$value])){
                    $warranty        = strtotime($this->warranty_date);
                    $warranty        = strtotime("+".$this->month." month", $warranty);
                    $warranty        = date('Y-m-d', $warranty);
                    $warranty_date   = $warranty;
                }

                if(!empty($this->year)){
                    $warranty        = strtotime($this->warranty_date);
                    $warranty        = strtotime("+".$this->year." year", $warranty);
                    $warranty        = date('Y-m-d', $warranty);
                    $warranty_date   = $warranty;
                }


            }
}  // this one

 ?>
于 2013-07-16T06:16:28.987 回答