function array_compare(&$ar1, &$ar2)
{
    if (gettype($ar1) != 'array' || gettype($ar2) != 'array') {
        return FALSE;
    }
    # first a shallow diff
    if (count($ar1) != count($ar2)) {
        return FALSE;
    }
    $diff = array_diff($ar1, $ar2);
    if (count($diff) == 0) {
        return TRUE;
    }
    # diff failed, do a full check of the array
    foreach ($ar1 as $k => $v) {
        #print "comparing $v == $ar2[$k]\n";
        if (gettype($v) == "array") {
            if (!array_compare($v, $ar2[$k])) {
                return FALSE;
            }
        } else {
            if (!string_compare($v, $ar2[$k])) {
                return FALSE;
            }
            if ($type == 'float') {
                # we'll only compare to 3 digits of precision
                $ok = number_compare($expect, $result, 3);
            }
            if ($type == 'boolean') {
                $ok = boolean_compare($expect, $result);
            } else {
                $ok = string_compare($expect, $result);
            }
        }
    }
    return TRUE;
}
예제 #2
0
 /**
  * Compares two PHP types for a match.
  *
  * @param mixed $expect
  * @param mixed $test_result
  *
  * @return boolean
  */
 function compareResult(&$expect, &$result, $type = null)
 {
     $expect_type = gettype($expect);
     $result_type = gettype($result);
     if ($expect_type == 'array' && $result_type == 'array') {
         // compare arrays
         return array_compare($expect, $result);
     }
     if ($type == 'float') {
         // We'll only compare to 3 digits of precision.
         return number_compare($expect, $result);
     }
     if ($type == 'boolean') {
         return boolean_compare($expect, $result);
     }
     return string_compare($expect, $result);
 }