Re: switch()

From: Date: Tue, 29 Aug 2006 18:44:55 +0000
Subject: Re: switch()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-241190@lists.php.net to get a copy of this message
On Tuesday 29 August 2006 13:31, afan@afan.net wrote: > I have something like this: > > <?php > $query = mysql_query(" > SELECT col_1, col_2 > FROM table > "); > $result = mysql_fetch_array($query); > if ($result['col_1'] == 'value_1') > { > // do something > } > > if ($result['col_2'] == 'value_2') > { > // do something > } > ?> > > when I tried to use swiitch() > <?php > switch (true) > { > case ($result['col_1'] == 'value_1'): > // do something > break; > > case ($result['col_2'] == 'value_2'): > // do something > break; > } > ?> > > it will give me only the first true case. if $result['col_1'] == 'value_1' > is true 2nd case will never be executed? > Does it mean I CANNOT use switch() in this case? > > -afan Using a switch like this is more equivalent of if(something){ // true } else { // false } You're doing : if(something1){ // true 1 } if(something2){ // true2 } hope that helps. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099

« previous php.general (#241190) next »