Frank Thornton Frank Thornton - 2 months ago 5x
PHP Question

Comparing dynamic arrays together with an if then else statement

In my code I want to replace the following:

if($file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE"){}

with something like this that can be changed in a more generic config file:


The values of both arrays change and vary. What I want to do is if the
matches the value of
is to skip over it.

I am going in the right direction by trying something like this. So far I've not had any success.

$myArray = explode(',', $domains_to_exclude);
$count = count($file);
for ($i=1; $i<$count; $i++)
if ($myArray[$i] !== $file['domain'])
$domainn = str_replace("", "", $domain);
echo'<option value="'.$domain.'">'.$domainn.'</option>';
else {}

$myArray = explode(',', $domains_to_exclude);
if (!in_array($file['domain'], $myArray)) {
    // Domain is ok, process file

in_array($str, $arr) checks if any of the values in $arr equals $str.

And also, you don't have to have that else block there if it is empty. But it won't affect your code negatively either.