douna2633 2018-11-13 09:15
浏览 48
已采纳

Php:检查是否存在查询以及是否传递GET参数的可靠方法

Really new to PHP...

I would like to have a PHP interface which takes day, month, and year arguments as 'd', 'm', 'y', where the default values are simply pulled from the current date.

My thinking is that that should look something like this:

$day = isset($_GET) && isset($_GET['d']) ? $_GET['d'] : date('d');

But I seem to be missing something. Do I need the first isset($_GET) or is that redundant?

  • 写回答

1条回答 默认 最新

  • dqm83011 2018-11-13 09:17
    关注

    $_GET is always going to be set, so yes - that part is redundant.

    $day = isset($_GET['d']) ? $_GET['d'] : date('d');
    

    This would be fine for any PHP version, including PHP 5.x.

    In PHP 7 you can shorten this by using the null coalescing operator:

    $day = $_GET['d'] ?? date('d');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?