note 116477 added to function.boolval
| From: | MattM | Date: | Fri, 09 Jan 2015 05:27:46 +0000 |
| Subject: | note 116477 added to function.boolval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201390@lists.php.net to get a copy of this message | ||
To anyone like me who came here looking for a way to turn any value into a 0/1 that will fit into a
MySQL boolean (tinyint) field:
<?php
$tinyint = (int) filter_var($valToCheck, FILTER_VALIDATE_BOOLEAN);
?>
tinyint will be 0 (zero) for values like string "false", boolean false, int 0
tinyint will be 1 for values like string "true", boolean true, int 1
Useful if you are accepting data that might be from a language like Javascript that sends string
"false" for a boolean false.
----
Server IP: 72.52.91.14
Probable Submitter: 68.47.202.161
----
Manual Page -- http://php.net/manual/en/function.boolval.php
Edit -- https://master.php.net/note/edit/116477
Del: integrated -- https://master.php.net/note/delete/116477/integrated
Del: useless -- https://master.php.net/note/delete/116477/useless
Del: bad code -- https://master.php.net/note/delete/116477/bad+code
Del: spam -- https://master.php.net/note/delete/116477/spam
Del: non-english -- https://master.php.net/note/delete/116477/non-english
Del: in docs -- https://master.php.net/note/delete/116477/in+docs
Del: other reasons-- https://master.php.net/note/delete/116477
Reject -- https://master.php.net/note/reject/116477
Search -- https://master.php.net/manage/user-notes.php