wp_fuzzy_number_match

函式
wp_fuzzy_number_match ( $expected, $actual, $precision = 1 )
引數
  • (int|float) $expected The expected value.
    Required:
  • (int|float) $actual The actual number.
    Required:
  • (int|float) $precision The allowed variation.
    Required:
    Default: 1
返回值
  • (bool) Whether the numbers match within the specified precision.
定義位置
相關方法
wp_notify_moderatorwp_ajax_oembed_cachewp_insert_attachmentwp_ajax_query_attachmentswp_nav_menu_max_depth
引入
5.3.0
棄用
-

wp_fuzzy_number_match: 這個函式用於將一個數字與一個模糊值列表相匹配,如”少數”、”幾個”、”許多”等。它接受一個數字作為引數並返回相應的模糊值。

檢查兩個數字是否接近相同。

這類似於使用 `round()`,但精度更細微。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
return abs( (float) $expected - (float) $actual ) <= $precision;
}
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) { return abs( (float) $expected - (float) $actual ) <= $precision; }
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
	return abs( (float) $expected - (float) $actual ) <= $precision;
}

常見問題

FAQs
檢視更多 >