[英]How to check whether GET is empty?
I am setting some vars from GET
我正在从
GET
设置一些变量
$start = $_GET['start'];
$end = $_GET['end'];
From which I get: 从中我得到:
start=1-11-2018&end=30-11-2018
And then I am doing: 然后我在做:
if((!$start) && (!$end)) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
} else {
echo "no dates";
}
And to close it 并关闭它
if((!$start) && (!$end)) {
}
}
But this isn't happening 但这没有发生
if((!$start) && (!$end)) {
UPDATE 更新
Now this is working but it doesn't go in else if no GET 现在这是可行的,但是如果没有GET,它将无法进入
if((!empty($_GET['start'])) && (!empty($_GET['end']))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
} else {
echo "No dates";
}
if you are calling : http://example.com?start=1-11-2018&end=30-11-2018
如果您拨打电话: http : //example.com?start=1-11-2018&end=30-11-2018
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...";
}
This is how I resolved it: 这是我解决的方法:
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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.