PHP - How to Convert the String to a Boolean
Learn, how to convert a string to boolean value in PHP.
To convert a string to boolean, we can use the triple equals operator ===
in PHP.
Here an example:
$str = 'true';
$bool = ($str === 'true');
var_dump($bool);
Output:
bool(true)
In above code, we are comparing the string to the string value'true'
. If the both values are same the condition will return boolean value true otherwise false.
The triple equals operator checks both left hand side operator and right hand side operator should be same. If both are same it returns “true” otherwise it returns “false”.