Re: "My truth comes out" [1]
| From: | Adam Richardson | Date: | Thu, 21 Oct 2010 18:40:57 +0000 |
| Subject: | Re: "My truth comes out" [1] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308960@lists.php.net to get a copy of this message | ||
On Thu, Oct 21, 2010 at 5:39 AM, Gary <php-general@garydjones.name> wrote:
> Is there any nice way to convert a string containing either "TRUE" or
> "FALSE" to a bool with the appropriate value? I know I can just "if
> (strcmp..." but, as the song goes on to say "...ugly, so ugly, it's
> ugly"[1]
>
> Footnotes:
> [1] "Mask", Henry Rollins
>
> --
> Gary
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You don't need an 'if', and you don't need to add a function call to the
stack:
$value_to_convert = 'TRUE'; // tested with true, but works with false, too
$bool = ('TRUE' == $value_to_convert);
This does require that you've sanity checked the value before hand, as your
"either "TRUE" or "FALSE"" statement implies.
Adam
--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com