rest_validate_array_contains_unique_items( array $array )

Checks if an array is made up of unique items.


Parameters Parameters

$array

(array) (Required) The array to check.


Top ↑

Return Return

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


Top ↑

Source Source

File: wp-includes/rest-api.php

function rest_validate_array_contains_unique_items( $array ) {
	$seen = array();

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

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

			continue;
		}

		return false;
	}

	return true;
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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