Hey Brandon,
Thanks for spotting this, btw! Neat little bug.
Try this code. Replace the if-else section we've been discussing...
With this:
It checks for all scenarios and makes some educated decisions about what should be considered "equal" and "not equal" in cases where the value is actually an array.
I confess I haven't tested it, but it looks okay to me!
- Ben
Thanks for spotting this, btw! Neat little bug.
Try this code. Replace the if-else section we've been discussing...
PHP Code:
if ($comparison == "equal" && $fields[$field_to_check] != $value_to_check)
{
$satisfies_if_conditions = false;
break;
}
else if ($comparison == "not_equal" && $fields[$field_to_check] == $value_to_check)
{
$satisfies_if_conditions = false;
break;
}
With this:
PHP Code:
if ($comparison == "equal")
{
$fail = false;
// if the field being compared against doesn't exist, we reasonably say that the value won't be the same
if (!array_key_exists($field_to_check, $fields))
$fail = true;
// if the value being passed is an array (e.g. a checkbox / multi-select field), what would be considered
// "equal"? I think as long as the array contains AT LEAST that value, it's fair to pass this test
else if (is_array($fields[$field_to_check]) && in_array($field_to_check, $fields))
$fail = true;
// lastly, do a straight string test
else if ($fields[$field_to_check] != $value_to_check)
$fail = true;
if ($fail)
{
$satisfies_if_conditions = false;
break;
}
}
else if ($comparison == "not_equal")
{
$fail = true;
if (!array_key_exists($field_to_check, $fields))
$fail = false;
else if (is_array($fields[$field_to_check]) && !in_array($field_to_check, $fields))
$fail = false;
else if ($fields[$field_to_check] != $value_to_check)
$fail = false;
if ($fail)
{
$satisfies_if_conditions = false;
break;
}
$satisfies_if_conditions = false;
break;
}
It checks for all scenarios and makes some educated decisions about what should be considered "equal" and "not equal" in cases where the value is actually an array.
I confess I haven't tested it, but it looks okay to me!
- Ben