Checks if an array is made up of unique items.
Parameters
$input_array
arrayrequired- The array to check.
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;
}
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.