darkfreaks Posted February 20, 2010 Share Posted February 20, 2010 okay i spent all yesterday making like 300 if statements into one giant switch statement would it shorten the code any if i made it into an array statement? case ($line==''.$reason.' Reason.'): $message = $line.$user; break; i need something like that put into an array statement if possible Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2010 Share Posted February 20, 2010 Just put a list of the possible values into an array and use in_array() to test if $line is one of the values to determine if $message should be set to $message = $line.$user; Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015252 Share on other sites More sharing options...
darkfreaks Posted February 20, 2010 Author Share Posted February 20, 2010 how would i use in_array to match the values to line? wouldnt that check just to see if the reason was in the array? Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015295 Share on other sites More sharing options...
darkfreaks Posted February 20, 2010 Author Share Posted February 20, 2010 would this possibly work for an assoc array $array=array("$reason"=>"reason."); if(in_array($array) && $array==$line){ $message = $line.$user; } Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015309 Share on other sites More sharing options...
darkfreaks Posted February 20, 2010 Author Share Posted February 20, 2010 oops i got the last part backwards HAHA it is sposed to be && $line==$array but that will make sure it matches everything in the array right?> Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015321 Share on other sites More sharing options...
darkfreaks Posted February 20, 2010 Author Share Posted February 20, 2010 on second thought that wont output the whole array will it Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015349 Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2010 Share Posted February 20, 2010 There's really no way you can effectively use a function in a programming language until you have studied the documentation so that you know what it accepts as parameters, what operation it performs, and what value it returns - http://us2.php.net/in_array Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015372 Share on other sites More sharing options...
darkfreaks Posted February 20, 2010 Author Share Posted February 20, 2010 from what i gather in_array just checks whether a value is in the array i need a way to match the array withe the $line variable. Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015380 Share on other sites More sharing options...
PFMaBiSmAd Posted February 21, 2010 Share Posted February 21, 2010 You have not exactly provided any information showing what you are trying to accomplish and what the result should be for any given data. Based on the code in your previous thread, doing what I stated in this thread will work. Quote Link to comment https://forums.phpfreaks.com/topic/192730-form-help-with-switch-to-array/#findComment-1015695 Share on other sites More sharing options...
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.