Jump to content

[SOLVED] checking an array for a value and assigning a file to it


Taos18

Recommended Posts

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

}

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.