rest_are_values_equal() WordPress Function

The rest_are_values_equal() function is used to check if all values in an array are equal. This function is useful for checking if an array contains only one value.

rest_are_values_equal( mixed $value1, mixed $value2 ) #

Checks the equality of two values, following JSON Schema semantics.


Description

Property order is ignored for objects.

Values must have been previously sanitized/coerced to their native types.


Top ↑

Parameters

$value1

(mixed)(Required)The first value to check.

$value2

(mixed)(Required)The second value to check.


Top ↑

Return

(bool) True if the values are equal or false otherwise.


Top ↑

Source

File: wp-includes/rest-api.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More