wpseek.com
A WordPress-centric search engine for devs and theme authors



rest_validate_array_contains_unique_items › WordPress Function

Since5.5.0
Deprecatedn/a
rest_validate_array_contains_unique_items ( $input_array )
Parameters:
  • (array) $input_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( $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;
		}

		return false;
	}

	return true;
}