>From the manual at www.php.net. This is a lot more sophiticated than mine and apparantly works. So as a recent user of PHP, I'm at a loss as to what is and what isn't.
Using switch would be more efficiant as it would stop once a match is made (if you use break), but with eleif statements each one is evaluated in order. $chr = substr($a,$i,1); switch (TRUE) { case $chr == "á" || $chr == "à" || $chr == "ã" || $chr == "â": $a = str_replace(substr($a,$i,1),"a",$a); break; case $chr == "é" || $chr == "è" || $chr == "ê": $a = str_replace(substr($a,$i,1),"e",$a); break; } ----- Original Message ----- From: "Sean Malloy" <[EMAIL PROTECTED]> To: "PHP General" <[EMAIL PROTECTED]> Sent: Thursday, December 19, 2002 9:36 PM Subject: RE: [PHP] Another problem with conditional statements > Nowhere in the documentation does it specify switch should be used in the > context you are attempting. > > The docs show a single variable and checking the case of that variable. > > I'm not going to berate you on syntax. If you can get it working like that > then good for you. However, I would strongly advise you to use the > if/elseif/else statements instead. > > an example of switch > > $action = $_POST['action'] > switch ($action) > { > case 'help': showHelp(); break; > default : showDefault(); > } > > not > > $action = $_POST['action'] > switch (true) > { > case ($action == 'help'): showHelp(); break; > default : showDefault(); > } > > > > -----Original Message----- > > From: Beauford.2002 [mailto:[EMAIL PROTECTED]] > > Sent: Friday, 20 December 2002 12:46 PM > > To: Rick Emery > > Cc: PHP General > > Subject: Re: [PHP] Another problem with conditional statements > > > > > > I believe you are incorrect. Switch will look for the first case statement > > that is true and execute that statement. The following works - case one is > > incorrect so it doesn't get executed but the second case does. Paste this > > into a test.php file and you will see it works.. Read the manual. > > > > $a=2; > > $b=4; > > > > switch (true) { > > case ($a < $b) and ($b > 5): > > echo "Incorrect"; > > case ($a == 2): > > echo "Correct"; > > } > > > > So my original question is still stands. The switch statement is correct, > > but there is a problem with my conditional statements. > > > > ----- Original Message ----- > > From: "Rick Emery" <[EMAIL PROTECTED]> > > To: "Beauford.2002" <[EMAIL PROTECTED]>; "PHP General" > > <[EMAIL PROTECTED]> > > Sent: Thursday, December 19, 2002 7:33 PM > > Subject: Re: [PHP] Another problem with conditional statements > > > > > > > switch() does not work that way. Switch uses the value in the > > parentheses > > and selects a > > > CASE based upon that value. Read the manual. > > > > > > You will have to use a series of if()-elseif()-else() > > > ----- Original Message ----- > > > From: "Beauford.2002" <[EMAIL PROTECTED]> > > > To: "PHP General" <[EMAIL PROTECTED]> > > > Sent: Thursday, December 19, 2002 6:19 PM > > > Subject: [PHP] Another problem with conditional statements > > > > > > > > > Hi, > > > > > > This should be as simple as breathing, but not today. I have > > two variables > > > $a and $b which I need to compare in a switch statement in several > > different > > > ways, but no matter what I do it's wrong. > > > > > > This is what I have tried, can someone tell me how it should be. > > > > > > TIA > > > > > > switch (true): > > > > > > case ($a == $b): This one seems simple enough. > > > do sum stuff; > > > break; > > > > > > case ($a && $b == 124): This appears not to work. > > > do sum stuff; > > > break; > > > > > > case ($a == 124 && $b == 755): If $a is equal to 124 and > > $b is equal > > to > > > 755 then it should be true..doesn't work. > > > do sum stuff; > > > break; > > > > > > case ($a == 124 && $b != 124): Nope, this doesn't appear to work > > > either. > > > do sum stuff; > > > break; > > > > > > endswitch; > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php