Ben-Nasha Posted January 6, 2010 Posted January 6, 2010 i am learning the switch statment... pleaet tell me if this is right... <?php include "globals.php"; $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; switch($_GET['x']) { case 'lexus' : lexus (); break; case 'mustang' : mustang (); break; case 'fordgt': fordgt (); break; case 'fait' : fait (); break; default : index (); break; } function index() { echo '<h3>GTA</h3> '; echo' [url="?x=lexus"]Break into a lexus[/url] '; echo ' <a hrerf="?x=mustang">Break into a mustang</a> '; echo ' [url="?x=fordgt"]Break into a ford gt[/url] '; echo ' [url="?x=fait"]Break into a fait[/url] '; } function lexus() { echo'lol'; } ?> NOTE:its not finished! Quote
Ben-Nasha Posted January 6, 2010 Author Posted January 6, 2010 code ok dayo ill try to finish it all tommrow Quote
MDK666 Posted January 6, 2010 Posted January 6, 2010 i am learning the switch statment... pleaet tell me if this is right... include "globals.php"; $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; switch($_GET['x']) { case 'lexus' : lexus (); break; case 'mustang' : mustang (); break; case 'fordgt': fordgt (); break; case 'fait' : fait (); break; default : index (); break; } function index() { echo 'GTA '; echo' Break into a lexus '; echo ' Break into a mustang '; echo ' Break into a ford gt '; echo ' Break into a fait '; } function lexus() { echo'lol'; } ?> NOTE:its not finished! that should work but you dont have to use 2 lines on it you can just use if(!$_GET['action']) or name it whatever u want instead of useing $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; switch($_GET['x']) then all the links would be http://blabla.com/index.php?action= or whatever you called it. hope that helps Quote
Ben-Nasha Posted January 7, 2010 Author Posted January 7, 2010 2 lines so is this right? <?php include "globals.php"; if(!$_GET['action']) { case 'bread' : bread (); break; case 'chicken' : chicken (); break; case 'ham' : ham (); break; case 'crisps' : crisps (); break; ?> Quote
Zeggy Posted January 7, 2010 Posted January 7, 2010 Nope, now it's wrong. Stick with your original code, it's much better and it works :P Quote
Danny696 Posted January 7, 2010 Posted January 7, 2010 Ben, just ignore MDK666, your learning switch, not if Quote
MDK666 Posted January 7, 2010 Posted January 7, 2010 Ben, just ignore MDK666, your learning switch, not if acually ben the if that i had posted works also, i use it all the time, so yea mine does work so yea Quote
Zero-Affect Posted January 7, 2010 Posted January 7, 2010 $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; seems abit far lol but i normally add in_array for a little extra security Quote
CrazyT Posted January 11, 2010 Posted January 11, 2010 $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; seems abit far lol but i normally add in_array for a little extra security You don't need in_array() for a little extra security, while using switch() there. It's not needed, when using switch if x value isn't in switch, it will just use the default value. Quote
Danny696 Posted January 11, 2010 Posted January 11, 2010 MDK, i know it works, just saying that ben wants to learn switch Quote
Zero-Affect Posted January 12, 2010 Posted January 12, 2010 $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; seems abit far lol but i normally add in_array for a little extra security You don't need in_array() for a little extra security, while using switch() there. It's not needed, when using switch if x value isn't in switch, it will just use the default value. depends on if they are using switch as Above one didn't but you are right. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.