WordPress开发者和主题制作者的搜索引擎



rest_is_boolean ›

Since4.7.0
已弃用n/a
rest_is_boolean ( $maybe_bool )
参数:
  • (bool|string) $maybe_bool The value being evaluated.
    Required: Yes
返回:
  • (boolean) True if a boolean, otherwise false.
定义在:
文档:

Determines if a given value is boolean-like.



源码

function rest_is_boolean( $maybe_bool ) {
	if ( is_bool( $maybe_bool ) ) {
		return true;
	}

	if ( is_string( $maybe_bool ) ) {
		$maybe_bool = strtolower( $maybe_bool );

		$valid_boolean_values = array(
			'false',
			'true',
			'0',
			'1',
		);

		return in_array( $maybe_bool, $valid_boolean_values, true );
	}

	if ( is_int( $maybe_bool ) ) {
		return in_array( $maybe_bool, array( 0, 1 ), true );
	}

	return false;
}