NYCPHP Meetup

NYPHP.org

[nycphp-talk] range in switch/case (bug?)

jon baer jonbaer at jonbaer.net
Thu Feb 5 17:18:23 EST 2004


hey - here is an example (but i just ran this as a test and my result for 0 was not what i expected, hmm - seems it automatically cast the 0 into a FALSE im guessing):

<?php
 
 for ($x = 0; $x < 10; $x++) {
   switch ($x) {
   
  case ($x < 3 || $x > 6):
   echo "x = $x: yes!\n";
   continue;
  default:
   echo "x = $x: no!\n";
   break;
   
  }
  
 }
 
?>

Result:

Jon Baer at thinkpad /mnt/desktop
$ php test.php
x = 0: no!
x = 1: yes!
x = 2: yes!
x = 3: no!
x = 4: no!
x = 5: no!
x = 6: no!
x = 7: yes!
x = 8: yes!
x = 9: yes!
  ----- Original Message ----- 
  From: Ophir Prusak 
  To: NYPHP Talk 
  Sent: Thursday, February 05, 2004 4:38 PM
  Subject: Re: [nycphp-talk] range in switch/case



  If you really want to use switch, you can use use switch (TRUE) and in the case something like ($a < 10 && $a > 100).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040205/7fdba297/attachment.html>


More information about the talk mailing list