Php 如何检查GET是否为空?
我正在从Php 如何检查GET是否为空?,php,Php,我正在从GET $start = $_GET['start']; $end = $_GET['end']; 我从中得到: start=1-11-2018&end=30-11-2018 然后我在做: if((!$start) && (!$end)) { if (($dateFormat >= $start) && ($dateFormat <= $end)) { } else { echo "no dates"; } 但这并没
GET
$start = $_GET['start'];
$end = $_GET['end'];
我从中得到:
start=1-11-2018&end=30-11-2018
然后我在做:
if((!$start) && (!$end)) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
} else {
echo "no dates";
}
但这并没有发生
if((!$start) && (!$end)) {
更新
现在这是工作,但它没有进入其他如果没有得到
if((!empty($_GET['start'])) && (!empty($_GET['end']))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
} else {
echo "No dates";
}
if((!empty($\u GET['start'])和(!empty($\u GET['end'])){
如果($dateFormat>=$start)&($dateFormat我就是这样解决的:
if((!empty($start)) && (!empty($end))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
}
// here the content which
// in case those vars are not empty,
// would get filtered by that logic.
if((empty($start)) && (empty($end))) {
// Close the condition for second if when not empty
} else {
echo "No dates";
}
if((!empty($start))&&(!empty($end))){
如果(($dateFormat>=$start)&($dateFormat通过isset()检查)
如果您正在拨打:
if(isset($\u GET['start'])和&isset($\u GET['end']){//检查GET方法是否已设置
如果((!empty($\u GET['start'])和(!empty($\u GET['end'])){
如果($dateFormat>=$start)&($dateFormat)和($dateFormat怎么办?@Swellar check updated question你的问题是什么,其中一个日期可以是空的,代码可以执行?可能if(!empty($\u GET['start'])和&!empty($\u GET['end']){
是你想要的。@IdontDownVote我想问题是我正在关闭第二个if.@rob m关闭你的嵌套if(如果($dateFormat>=$start)&($dateFormat)您检查了两次$start
,而不是$end
,那么也有额外的()
s。这看起来像是我的评论。@user3783243是的,是一个打字错误,更新了它。为什么要否决投票?@user3783243不,这不像你的评论,因为我在那一秒仍然有错误的结束括号位置。如果不确定否决票,我就没有投票。你的意思是因为打字错误,它不像我的评论?如果(!empty($\u GET['start'])&!empty($_GET['end']){
看起来和你做的一模一样。@user3783243没有。如果你检查我的代码,不管这个检查是否为空,你可以看到我在第一个If内关闭了第二个If},这就是为什么没有出现echo“no dates”,我必须在底部关闭}否则{
在If之后(($dateFormat>=$start)&&($dateFormat)
if((!empty($start)) && (!empty($end))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
}
// here the content which
// in case those vars are not empty,
// would get filtered by that logic.
if((empty($start)) && (empty($end))) {
// Close the condition for second if when not empty
} else {
echo "No dates";
}
1. The isset() is checking query string "start"/"end" is having or not.
2. The empty() is checking query string "start"/"end" is empty/blank or not
if( isset($_GET['start']) && isset($_GET['end']) ){ // check the GET method is set or not
if((!empty($_GET['start'])) && (!empty($_GET['end']))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
}
else {
echo "Empty dates";
}
}
else{
echo "Start / End date query string is missing...";
}