Beispiel #1
0
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;
            }
        } elseif (is_object($v)) {
            if (!object_compare($v, $ar2[$k])) {
                return false;
            }
        } else {
            if (!string_compare($v, $ar2[$k])) {
                return false;
            }
        }
    }
    return true;
}
Beispiel #2
0
function compare(&$x, &$y)
{
    $ok = 0;
    $x_type = gettype($x);
    $y_type = gettype($y);
    if ($x_type == $y_type) {
        if ($x_type == "array") {
            $ok = array_compare($x, $y);
        } else {
            if ($x_type == "object") {
                $ok = object_compare($x, $y);
            } else {
                if ($x_type == "double") {
                    $ok = number_compare($x, $y);
                    //    } else if ($x_type == 'boolean') {
                    //      $ok = boolean_compare($x, $y);
                } else {
                    $ok = $x == $y;
                    //      $ok = string_compare($expect, $result);
                }
            }
        }
    }
    return $ok;
}