I want to simplify an IF statement that I have.
Basically, it's checking if a user is logged in, and if not, what action they are performing. If they are trying to access a portion of the site they can't because they aren't logged in, it returns an error. Needless to say, this statement is VERY long.
I've been experimenting with 2 ideas, but no success.
First was to access an array, do the checking, and return the value FALSE or TRUE. It went something like:
if (doCheck() == 'TRUE')
{
// echo success statement
}
elseif (doCheck() == 'FALSE')
{
// echo failure statement
}
else
{
// echo TOTAL failure statement
}
And I get the TOTAL failure error message.
This is my function:
function doCheck()
{
if (isset($INFO['userCookie']))
{
return TRUE;
}
elseif (!isset($INFO['userCookie']))
{
return FALSE;
}
}
Then I wanted to do the IF checking using an array of known values, and if it matched any of those, it would do something.
I wasn't sure on the implementation of this, so I realized I'm over my head. It might work using a for loop, if I knew how many items were in the array. But then that might take too much overhead. I couldn't find anything online that was able to do what I wanted.
I honestly think the function method would be best if I could get it working.
Does anybody have any insight on this particular problem?
Thanks!