php - 如何检查GET是否为空?
问题描述
我正在设置一些变量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((!$start) && (!$end)) {
更新
现在这正在工作,但如果没有 GET,它就不会进入 else
if((!empty($_GET['start'])) && (!empty($_GET['end']))) {
if (($dateFormat >= $start) && ($dateFormat <= $end)) {
} else {
echo "No dates";
}
解决方案
通过 isset() 检查
如果您打电话: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...";
}
推荐阅读
- math - 找到最小标准偏差的最佳方法
- java - 项目构建错误:不可解析的父 POM fo
- html - 如何在 asp.net 项目中链接 css 文件?
- matrix - 非正定矩阵的特征中的共轭梯度
- javascript - *ngFor 在 Angular 5 引导模式中不起作用
- c# - 在 IUrlHelper.GetVirtualPathData 中不遵守使用 IApplicationModelConvention 的自定义本地化路由
- javascript - ng build --prod 不生成 dist 文件夹
- javascript - 单击 HTML 表单中的提交按钮后无法重定向
- java - 扩展 log4j/slf4j 记录器
- javascript - 用户在网站上传的 SVG 图像的路径