rest_are_values_equal

The timeline below displays how wordpress function rest_are_values_equal has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 7.1

/**
 * Checks the equality of two values, following JSON Schema semantics.
 *
 * Property order is ignored for objects.
 *
 * Values must have been previously sanitized/coerced to their native types.
 *
 * @since 5.7.0
 *
 * @param mixed $value1 The first value to check.
 * @param mixed $value2 The second value to check.
 * @return bool True if the values are equal or false otherwise.
 */
function rest_are_values_equal($value1, $value2)
{
    if (is_array($value1) && is_array($value2)) {
        if (count($value1) !== count($value2)) {
            return false;
        }
        foreach ($value1 as $index => $value) {
            if (!array_key_exists($index, $value2) || !rest_are_values_equal($value, $value2[$index])) {
                return false;
            }
        }
        return true;
    }
    if (is_int($value1) && is_float($value2) || is_float($value1) && is_int($value2)) {
        return (float) $value1 === (float) $value2;
    }
    return $value1 === $value2;
}

WordPress Version: 5.7

/**
 * Checks the equality of two values, following JSON Schema semantics.
 *
 * Property order is ignored for objects.
 *
 * Values must have been previously sanitized/coerced to their native types.
 *
 * @since 5.7.0
 *
 * @param mixed $value1 The first value to check.
 * @param mixed $value2 The second value to check.
 * @return bool True if the values are equal or false otherwise.
 */
function rest_are_values_equal($value1, $value2)
{
    if (is_array($value1) && is_array($value2)) {
        if (count($value1) !== count($value2)) {
            return false;
        }
        foreach ($value1 as $index => $value) {
            if (!array_key_exists($index, $value2) || !rest_are_values_equal($value, $value2[$index])) {
                return false;
            }
        }
        return true;
    }
    return $value1 === $value2;
}