PHP: Check if variable exist but also if has a value equal to something

前端 未结 13 1765
抹茶落季
抹茶落季 2020-12-01 13:46

I have (or not) a variable $_GET[\'myvar\'] coming from my query string and I want to check if this variable exists and also if the value corresponds to somethi

13条回答
  •  鱼传尺愫
    2020-12-01 14:28

    My question is, exist any way to do this without declare the variable twice?

    No, there is no way to do this correctly without doing two checks. I hate it, too.

    One way to work around it would be to import all relevant GET variables at one central point into an array or object of some sort (Most MVC frameworks do this automatically) and setting all properties that are needed later. (Instead of accessing request variables across the code.)

提交回复
热议问题