
利用Query Monitor插件调试WordPress并提高网站性能
rest_validate_array_contains_unique_items ( $array )
rest_validate_array_contains_unique_items: 这是一个WordPress的函数,验证一个数组是否只包含唯一的值: 该函数接受一个数组参数,如果数组中的任何值不是唯一的,则返回一个错误信息。
检查一个数组是否是由唯一的项组成的。
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; }