rest_validate_array_contains_unique_items() WordPress Function
The rest_validate_array_contains_unique_items() function is used to validate that an array contains only unique items. This is useful when validating user input, to ensure that duplicate values are not entered.
rest_validate_array_contains_unique_items( array $array ) #
Checks if an array is made up of unique items.
Parameters
- $array
(array)(Required)The array to check.
Return
(bool) True if the array contains unique items, false otherwise.
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;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |