是否有一个isdate PHP函数?

时间:2017-06-07 00:29:51

标签: php date if-statement

我在下面的用户函数中看到了一个名为isdate的内置函数,当我检查PHP文档时,我没有找到它。它是否存在以及它做了什么;或者这只是一个错字?

function mystery($a, $b, $c) {
$result = null;
if (strlen(trim($a)) == 0) {
    $result = $c;
}
else {
    if (strtolower(trim($b)) == "n") {
        if (!is_numeric($a)) {
            $result = $c;
        }
        else {
            $result = trim($a);
        }
    }
    else {
        if (strtolower(trim($b)) == "d") {
            if (!isdate($a)) {
                $result = $c;
            }
            else {
                $result = trim($a);
            }
        }
        else {
            $result = $a;
        }
    }
}
return($result);
}

1 个答案:

答案 0 :(得分:3)

也许,这不是一个真正的答案,因为我不知道原来的功能是什么,说实话我不在乎。无论如何,你可以做几个简化,使其更具可读性,避免重复处理,无用的$result变量,特别是删除这些不可读的嵌套if / else,换句话说,删除所有这些无用的噪音:

function mystery($a, $b, $c) {
    $trima = trim($a);

    if ( empty($trima) )
        return $c;

    $b = strtolower(trim($b));

    if ( $b == "n" )
        return is_numeric($trima) ? $trima : $c ;

    if ( $b == "d" )
        return isdate($trima) ? $trima : $c ;

    return $a;
}

我希望这可以帮助你理解这个函数应该做什么(也许上下文会有帮助)

相关问题