A WordPress-centric search engine for devs and theme authors



rest_validate_array_contains_unique_items ›

Since5.5.0
Deprecatedn/a
rest_validate_array_contains_unique_items ( $array )
Parameters:
  • (array) $array The array to check.
    Required: Yes
Returns:
  • (bool) True if the array contains unique items, false otherwise.
Defined at:
Codex:

Checks if an array is made up of unique items.



Source

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