rest_validate_array_contains_unique_items

The timeline below displays how wordpress function rest_validate_array_contains_unique_items has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Checks if an array is made up of unique items.
 *
 * @since 5.5.0
 *
 * @param array $input_array The array to check.
 * @return bool True if the array contains unique items, false otherwise.
 */
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;
}

WordPress Version: 5.5

/**
 * Checks if an array is made up of unique items.
 *
 * @since 5.5.0
 *
 * @param array $array The array to check.
 * @return bool True if the array contains unique items, false otherwise.
 */
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;
}