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 } Link to comment https://forums.phpfreaks.com/topic/120617-solved-checking-an-array-for-a-value-and-assigning-a-file-to-it/ 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. Link to comment https://forums.phpfreaks.com/topic/120617-solved-checking-an-array-for-a-value-and-assigning-a-file-to-it/#findComment-621521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.