PHP 8.5.0 Alpha 4 available for testing

Voting

: max(zero, four)?
(Example: nine)

The Note You're Voting On

Matt M
10 years ago
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.

<< Back to user notes page

To Top