In PHP (or any similar language), is there a better alternative to:
if(x >= 200 && x <= 299){
return 'ok';
}
My goal is to validate if a number is in the range of the 2xx code (for HTTP requests). I don't like the double-if clause because I must define the end of the range, and for some reason it's not practical when doing various automated validations.
In PHP (or any similar language), is there a better alternative to...
No there isn't, in my opinion.
Your code:
if (x >= 200 && x <= 299) {
return 'ok';
}
is very readable and clearly defines what is being checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With