Is there any builtin function for PHP that will take a boolean value and return its integer equivalent? 0 for FALSE, 1 for TRUE?
Of course you can easily create a function to do so, I'm just asking if there is a builtin function inside of PHP. I already tried intval()
and casting it to (int)
but they didnt work, they return 0 in both cases of TRUE and FALSE.
Edit : the problem was that it wasnt really a boolean, it was a string "false", "true", php didnt detect the jquery post that it passed a boolean. problem solved, thanks !
C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
0 is the integer value of zero, and false is the boolean value of, well, false.
The is_bool() function checks whether a variable is a boolean or not. This function returns true (1) if the variable is a boolean, otherwise it returns false/nothing.
The boolean values are called true and false in php. In the case of true , the output is 1 . While with the false , it does not show any output. It is worth noting that the browser always renders these values in strings.
Just add a "+" before your variable like this :
$myBool = true;
var_dump(+$myBool);
ouputs: int(1);
http://www.php.net/manual/en/language.types.integer.php
$myInt = (int)$myBoolean
should work
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