rest_validate_array_contains_unique_items( array $input_array ): bool

In this article

Checks if an array is made up of unique items.

Parameters

$input_arrayarrayrequired
The array to check.

Return

bool True if the array contains unique items, false otherwise.

Source

 * Checks if an array is made up of unique items.
 *
 * @since 5.5.0
 *
 * @param array $input_array The array to check.
 * @return bool True if the array contains unique items, false otherwise.
 */
function rest_validate_array_contains_unique_items( $input_array ) {
	$seen = array();

	foreach ( $input_array as $item ) {
		$stabilized = rest_stabilize_value( $item );
		$key        = serialize( $stabilized );

		if ( ! isset( $seen[ $key ] ) ) {
			$seen[ $key ] = true;

			continue;

Changelog

VersionDescription
5.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.