How to make quick judgement and assignment without isset()?

前端 未结 4 405
面向向阳花
面向向阳花 2021-01-16 20:51

I am tired of using code like:

$blog = isset($_GET[\'blog\']) ? $_GET[\'blog\'] : \'default\';

but I can\'t use:

$blog = $_         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 21:16

    No there is no shorter way than that. You can create a class that handles the $_POST and $_GET variables and just user it whenever you call the blog.

    Example:

    $blog = Input::put("blog");

    The input class will have a static method which will determine when input is either have a $_POST and $_GET or a null value.

提交回复
热议问题