note 47068 deleted from language.types.boolean by nlopess
| From: | nlopess@php.net | Date: | Tue, 02 Nov 2004 14:58:59 +0000 |
| Subject: | note 47068 deleted from language.types.boolean by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79505@lists.php.net to get a copy of this message | ||
Note Submitter: Jared
----
Discord's method is ok. But a bit bulky.
I wanted to use (bool) to ensure a field going into MySQL wasn't any greater than 1, and not
less than 0. That obviously isn't going to work too great with (bool).
So I found this nice method that can be used for other things as well.
$var = "false"
$var = ($var) ? 1 : 0;
Now strings can be bool'ed. 1, "1", "true", true, 2, -1, etc will end up
being 1. Anything that equalled 0 (0, "0", false, "false"), will return a 0.
Works for me! Now you'll get a 0 or 1, nothing else.