Jump to content

Coding Switch "Case" with multiple constants for same "Case"


azunoman

Recommended Posts

Didn't see how it could be done in php.net.

 

I have Switch and multiple Cases for various cart routines.  But for the following Case I can add a cart as:

 

case "Add Cart":

or in Spanish

case "Añadir al carro":

 

Can one code multiple constants in a single Case?  I am thinking rather than using the value of the submit button I should just pass a hidden value so I only need to check for one value.  Comments on both is most appreciated. 

Yes, you can do that.

 

For example:

<?php
$x = rand(0,100);
switch ($x) {
   case 0:
   case 10:
   case 20:
   case 30:
         echo $x . ' is either 0, 10, 20, or 30';
         break;
   case 5:
   case 95:
         echo 'Some other condition met';
         break;
   default:
         echo 'No conditions met';
}
?>

 

Ken

The value your submit button sends should be the same no matter what the label on the submit button is. If you are coding for a browser that doesn't work that way, then yes use a hidden form field to supply the same value no matter what submit button was selected.

 

Or, handle any language "normalization" at the start of your code so that the body of your code only sees a single value.

doh..that was not only easy...but super fast...that is why this is the place to go and to all that come here to ask ?'s...take to time to thank the best php freaks anywhere...thanks freaks!

 

my website is in development....I have to next tackle gettext... :o

 

how does one mark this as resolved...I did look but I getting old...

case "Add Cart":

case "Añadir al carro":

 

Interesting...PHP will not match on Añadir al carro.  If I take out the ñ it passes through the Case just fine.  I saw that Case was somewhat sensitive, php.net, so I went with hidden fields. 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.