rest_validate_array_contains_unique_items

函数


rest_validate_array_contains_unique_items ( $array )
参数
  • (array)
    $array
    The array to check.
    Required:
返回值
  • (bool) True if the array contains unique items, false otherwise.
定义位置
  • wp-includes/rest-api.php
    , line 1662
引入
5.5.0
弃用

检查一个数组是否是由唯一的项组成的。

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;
}