Taos18 Posted August 20, 2008 Share Posted August 20, 2008 I'm trying to shorten a switch or elseif statement by using an array. I have some numbers that I need to assign a file to.Example: $sub1=array("1","2","3"); $sub2=array("4","5","6"); $url=$SERVER['REQUEST_URI']; $test=strrchr($url,"="); //which gets me( =3 ) $test=str_replace("=","",$test); // now I have a number( 3) if ($test=$sub1) { $file=logo; } else { $file=logo1; I know this will not work but you get the idea. How can this be done } Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 have a look at in_array(). if you need more in-depth array analysis, consider array_intersect() and array_difference(), although i think for this application in_array() will work perfectly fine. Quote Link to comment 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.