Re: "My truth comes out" [1]

From: Date: Thu, 21 Oct 2010 11:48:43 +0000
Subject: Re: "My truth comes out" [1]
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-308927@lists.php.net to get a copy of this message
On 21 October 2010 12:42, Richard Quadling <rquadling@gmail.com> wrote: > On 21 October 2010 10:39, 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] > > What is the response when the string is NOT "TRUE" or "FALSE"? <?php $s_OriginalValue = 'FALSE'; $b_Test = in_array($s_Test = strtolower($s_OriginalValue), array('true', 'false')) ? !!strcmp($s_Test, 'false') : null; var_dump($b_Test); $s_OriginalValue = 'TRUE'; $b_Test = in_array($s_Test = strtolower($s_OriginalValue), array('true', 'false')) ? !!strcmp($s_Test, 'false') : null; var_dump($b_Test); $s_OriginalValue = 'GARBAGE'; $b_Test = in_array($s_Test = strtolower($s_OriginalValue), array('true', 'false')) ? !!strcmp($s_Test, 'false') : null; var_dump($b_Test); ?> outputs ... bool(false) bool(true) NULL But, really? What's wrong with if()? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.general (#308927) next »