Occasionally in PHP, you need to evaluate a string value to its boolean counterpart. One very common example of when this is needed is when you try to represent boolean in query string parameters. The jury is still out on the most appropriate way to represent a boolean value in Rest API or a query string, some of the
all of the values listed above are valid ways to represent a boolean value in your API or query string hence the need find a valid way to change the values correctly to their boolean value.
Evaluation using filter_var()
this filter_var method has been present in PHP since php5 and as the name implies, it filters a variable with a specified filter, for the purpose of this writeup, we are interested only in the boolean filter which is named FILTER_VALIDATE_BOOLEAN.
check the example below
filter_var("1", FILTER_VALIDATE_BOOLEAN) // => bool(true) filter_var("on", FILTER_VALIDATE_BOOLEAN) // => bool(true) filter_var("false", FILTER_VALIDATE_BOOLEAN) // => bool(false)