I have an if statement, and I need to compare a single string with many different options. The code I post below shows what I mean pretty clear. I know 2 ways of doing this, but the other is even longer. So, is there any function that makes something like this, but in a shorter way? It might seem silly what I asked for, but I expect the list of subpages to grow really fast. This is the code:
if (
$Url[0]=="contact"||
$Url[0]=="report"||
$Url[0]=="new"
)
{
//Do something
}
And I’d like to know if there’s something like this:
if ( weirdcomparefunction ($Url[0],"contact","report","new") )
{
//Do something
}
The problem I see to create my own function is that the number of variables passed is (ironically) variable.
Or even something like this:
$centered = array ("contact","report","new");
if ( weirdcomparefunction ($Url[0],$centered) )
{
//Do something
}
I’m also thinking about creating a .txt to store all the subpages with breaklines, but I’d need a big script so I’d like to know first if there is already a weirdcomparefunction(). Therefore it’d need to be SHORT, otherwise I’d have no problem making about 10-20 lines with some whiles and ifs.
Thank you all.
http://php.net/manual/en/function.in-array.php