Php 日期差异不起作用

Php 日期差异不起作用,php,datediff,Php,Datediff,我遇到以下错误“致命错误:无法在第334行的D:\xampp\htdocs\DHatch\front\myprofile.php中重新声明日期” My date_diff()函数是 function date_diff($d1, $d2){ $d1 = (is_string($d1) ? strtotime($d1) : $d1); $d2 = (is_string($d2) ? strtotime($d2) : $d2); $diff_secs = abs($d1 -

我遇到以下错误“致命错误:无法在第334行的D:\xampp\htdocs\DHatch\front\myprofile.php中重新声明日期”

My date_diff()函数是

function date_diff($d1, $d2){
    $d1 = (is_string($d1) ? strtotime($d1) : $d1);
    $d2 = (is_string($d2) ? strtotime($d2) : $d2);

    $diff_secs = abs($d1 - $d2);
    $base_year = min(date("Y", $d1), date("Y", $d2));

    $diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
    $diffArray = array(
        "years" => date("Y", $diff) - $base_year,
        "months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
        "months" => date("n", $diff) - 1,
        "days_total" => floor($diff_secs / (3600 * 24)),
        "days" => date("j", $diff) - 1,
        "hours_total" => floor($diff_secs / 3600),
        "hours" => date("G", $diff),
        "minutes_total" => floor($diff_secs / 60),
        "minutes" => (int) date("i", $diff),
        "seconds_total" => $diff_secs,
        "seconds" => (int) date("s", $diff)
    );
    if($diffArray['days'] > 0){
        if($diffArray['days'] == 1){
            $days = '1 day';
        }else{
            $days = $diffArray['days'] . ' days';
        }
        return $days . ' and ' . $diffArray['hours'] . ' hours ago';
    }else if($diffArray['hours'] > 0){
        if($diffArray['hours'] == 1){
            $hours = '1 hour';
        }else{
            $hours = $diffArray['hours'] . ' hours';
        }
        return $hours . ' and ' . $diffArray['minutes'] . ' minutes ago';
    }else if($diffArray['minutes'] > 0){
        if($diffArray['minutes'] == 1){
            $minutes = '1 minute';
        }else{
            $minutes = $diffArray['minutes'] . ' minutes';
        }
        return $minutes . ' and ' . $diffArray['seconds'] . ' seconds ago';
    }else{
        return 'Less than a minute ago';
    }
}

第334行中,该函数有一个结束括号

date\u diff
已在PHP中。您必须将此命名为其他名称或仅使用该名称。

您似乎无法理解:)不,它在开发服务器上工作,但在我的本地服务器上不工作。我在手册的前几行使用xamppLook-(PHP5>=5.3.0)。它听起来很好,但在我的开发服务器上运行良好。但不在本地服务器上工作。我使用xamppOr的效果更好,不要重新发明原生PHP函数,只需使用现有的
date\u diff