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.
No there isn’t, in my opinion.
Your code:
is very readable and clearly defines what is being checked.