保修日期错误 - strtotime

时间:2013-07-16 06:13:30

标签: 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;
        }


    }
}

请帮我查找此代码的错误。

此功能基于购买日期。
当我输入多个记录时,第一个保证日期显示为1970-01-01,第二个记录保修日期正确,其他人显示1970-01-01

1 个答案:

答案 0 :(得分: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

 ?>