balistic Posted August 12, 2007 Share Posted August 12, 2007 i have my switches all layed out, and they work when you do like file.php?action=whatever but how do i use them within a script. Can i call a case from within? like switch(action); or something, i did try that and it didnt work ._. thanks for any help guys Link to comment https://forums.phpfreaks.com/topic/64461-using-switches/ Share on other sites More sharing options...
marcus Posted August 12, 2007 Share Posted August 12, 2007 $action = $_GET['action']; if($action){ $array = array('put','your','actions','in','this','array'); if(in_array($action,$array)){ switch($action){ case put: include "inc/put.php"; break; case your: include "inc/your.php"; break; case actions: include "inc/actions.php"; break; case in: include "inc/in.php"; break; case this: include "inc/this.php"; break; case array: include "inc/array.php"; break; } }else { echo "Invalid action!\n"; } }else { echo "No action valid!\n"; } Link to comment https://forums.phpfreaks.com/topic/64461-using-switches/#findComment-321368 Share on other sites More sharing options...
balistic Posted August 12, 2007 Author Share Posted August 12, 2007 i dont want to use the switch like that though, i want to be able to just use it like a function within the script without requiring outside options. is there a way to do it like switch(1); or something. Link to comment https://forums.phpfreaks.com/topic/64461-using-switches/#findComment-321382 Share on other sites More sharing options...
balistic Posted August 12, 2007 Author Share Posted August 12, 2007 nvm i just used a function to use in both the switch and elsewhere. Link to comment https://forums.phpfreaks.com/topic/64461-using-switches/#findComment-321517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.