'How to make a condition that checks if value equals 1 or 0 without resulting in a boolean evaluation in PHP

I'm making an API and in one of the endpoints the variable user_type that can only be a 0 or a 1

api/user?user_type=0 || api/user?user_type=1

Inside my controller i check if the variable equals to one of those two values, the problem is that the comprobation results in a boolean one, and if in the endpoint i add a text value for user_type results in true because the variable exists.

Is there any way of evaluating without triggering a boolean result? Something like this:

if($variable != 0 && $variable != 1){ return true } //It should be false if $variable == 'text' and true if variable == 0 or 1


Solution 1:[1]

PHP8 satisfies your condition without any modification. Or you can use one of the below conditions - 0 and 1 within quotes. OR Check with ! == and ===

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Isha