You are here

function redirect_compare_array_recursive in Redirect 7.2

Same name and namespace in other branches
  1. 7 redirect.module \redirect_compare_array_recursive()

Compare that all values and associations in one array match another array.

We cannot use array_diff_assoc() here because we need to be recursive.

Parameters

$match: The array that has the values.

$haystack: The array that will be searched for values.

Return value

TRUE if all the elements of $match were found in $haystack, or FALSE otherwise.

2 calls to redirect_compare_array_recursive()
RedirectUnitTest::testCompareArrayRecursive in ./redirect.test
Test the redirect_compare_array_recursive() function.
redirect_load_by_source in ./redirect.module
Load multiple URL redirects from the database by {redirect}.source.

File

./redirect.module, line 1352

Code

function redirect_compare_array_recursive($match, $haystack) {
  foreach ($match as $key => $value) {
    if (!array_key_exists($key, $haystack)) {
      return FALSE;
    }
    elseif (is_array($value)) {
      if (!is_array($haystack[$key])) {
        return FALSE;
      }
      elseif (!redirect_compare_array_recursive($value, $haystack[$key])) {
        return FALSE;
      }
    }
    elseif ($value != $haystack[$key]) {
      return FALSE;
    }
  }
  return TRUE;
}