if(!isset($_GET['id']) with to different options with the same variable

前端 未结 2 1233
感动是毒
感动是毒 2021-01-29 15:36

I have this code: it works fine



        
相关标签:
2条回答
  • 2021-01-29 15:51

    Divide your condition in to two parts.

    1. First use the !isset condition and then
    2. Put the rest of condition inside if condition

    Your Code Look like this :

    if(!isset($_GET['id'])){
      $id = $_GET['id'];
      if($id == 1000 || $id == 2000) {
         // Action
      }
    }
    
    0 讨论(0)
  • 2021-01-29 16:13

    Use in_array and add all the values you want to check against into the array:

    if(!isset($_GET['id']) || !in_array($_GET['id'], array('1000', '2000'))){
        echo 'not 1k or 2 k';
    } else {
        echo 'is 1k or 2k';
    }
    

    Functional example: https://3v4l.org/Q2uao

    0 讨论(0)
提交回复
热议问题