mardi 23 mai 2017

Cleaning up a very long if statement

I have a very long list of strings called $stringfilter1 $stringfilter2 etc all the way up to $stringfilter50

I have another string $reporteremail and I want to make a conditional statement whereby if any of the $stringfilter strings is present in the $reporteremail, some code is executed. At the moment my code looks like this and it works:

if (stripos($reporteremail, $stringfilter1) !== false || stripos($reporteremail, $stringfilter2) !== false || stripos($reporteremail, $stringfilter3) !== false [...]) {
       runcode(); 
}

This is very very long though. I have cut it short here.

I was wondering if there's a cleaner, more efficient way to do this?

Aucun commentaire:

Enregistrer un commentaire