azunoman Posted October 7, 2008 Share Posted October 7, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127428-coding-switch-case-with-multiple-constants-for-same-case/ Share on other sites More sharing options...
kenrbnsn Posted October 7, 2008 Share Posted October 7, 2008 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 Link to comment https://forums.phpfreaks.com/topic/127428-coding-switch-case-with-multiple-constants-for-same-case/#findComment-659183 Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2008 Share Posted October 7, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127428-coding-switch-case-with-multiple-constants-for-same-case/#findComment-659189 Share on other sites More sharing options...
azunoman Posted October 7, 2008 Author Share Posted October 7, 2008 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... how does one mark this as resolved...I did look but I getting old... Link to comment https://forums.phpfreaks.com/topic/127428-coding-switch-case-with-multiple-constants-for-same-case/#findComment-659208 Share on other sites More sharing options...
azunoman Posted October 7, 2008 Author Share Posted October 7, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127428-coding-switch-case-with-multiple-constants-for-same-case/#findComment-659317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.