Re: Control Structure problem
| From: | Eugene Lee | Date: | Wed, 17 Sep 2003 04:45:34 +0000 |
| Subject: | Re: Control Structure problem | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162824@lists.php.net to get a copy of this message | ||
On Wed, Sep 17, 2003 at 01:29:26PM +1000, Tom Rogers wrote:
: Wednesday, September 17, 2003, 11:47:45 AM, Eugene Lee wrote:
:
: EL> The switch statement doesn't do an equivalency test, does it?
[...]
: EL> it doesn't do:
:
: EL> if (($var === 'TEST-1') ||
: EL> ($var === 'TEST-1') ||
: EL> ($var === 'TEST-1'))
: EL> {
: EL> do something
: EL> }
:
: You can do it this way I think :)
:
: switch (true) {
: case ($var === 'TEST-1')?true:false:
: case ($var === 'TEST-2')?true:false:
: case ($var === 'TEST-2')?true:false:
: do something
: }
Oh man, that's just sick...
I guess, for the sake of performance and readability, it's probably
easier to do an is_string($var) (or whatever variable type) before
doing a normal switch statement.
Still... that's just sick...