Double ternary. A better option?
Would there be a better way to validate a posted variable exists and validate strtotime works than t开发者_运维问答he following example?
$start = (!empty($_POST['start'])) ? (strtotime($_POST['start'])) ? strtotime($_POST['start']) : time() : time();
$start = (!empty($_POST['start']) && strtotime($_POST['start'])) ? strtotime($_POST['start']) : time();
I'd check it like $start = intval(strtotime($_POST['start']) > 0 ? intval(strtotime($_POST['start']) : time();
$startIsEmpty = empty($_POST['start']);
$startIsConvertible = strtotime($_POST['start']);
$start = !$startIsEmpty && $startIsConvertible ? strtotime($_POST['start']) : time();
精彩评论