The rest_are_values_equal() WordPress PHP function checks the equality of two values, following JSON Schema semantics.
Usage
$result = rest_are_values_equal( $value1, $value2 );
Example:
$value1 = array( 'key' => 'value' ); $value2 = array( 'key' => 'value' ); $result = rest_are_values_equal( $value1, $value2 ); // Output: true
Parameters
$value1
(mixed) – Required. The first value to check.$value2
(mixed) – Required. The second value to check.
More information
See WordPress Developer Resources: rest_are_values_equal()
Examples
Compare two integers
Check if the two given integers are equal.
$number1 = 10; $number2 = 10; $is_equal = rest_are_values_equal( $number1, $number2 ); // Output: true
Compare two strings
Check if the two given strings are equal.
$string1 = "Hello, world!"; $string2 = "Hello, world!"; $is_equal = rest_are_values_equal( $string1, $string2 ); // Output: true
Compare two arrays
Check if the two given arrays are equal, ignoring the order of their elements.
$array1 = array( 'one', 'two', 'three' ); $array2 = array( 'two', 'three', 'one' ); $is_equal = rest_are_values_equal( $array1, $array2 ); // Output: true
Compare two objects
Check if the two given objects are equal, ignoring the order of their properties.
$object1 = (object) array( 'first_name' => 'John', 'last_name' => 'Doe' ); $object2 = (object) array( 'last_name' => 'Doe', 'first_name' => 'John' ); $is_equal = rest_are_values_equal( $object1, $object2 ); // Output: true
Compare values of different types
Check if the two given values of different types are equal.
$number = 42; $string = "42"; $is_equal = rest_are_values_equal( $number, $string ); // Output: false