wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



rest_validate_array_contains_unique_items › WordPress Function

Depuis5.5.0
Dépréciéen/a
rest_validate_array_contains_unique_items ( $input_array )
Paramètres:
  • (array) $input_array The array to check.
    Requis: Oui
Retourne:
  • (bool) True if the array contains unique items, false otherwise.
Défini(e) dans:
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;
}