rest_get_best_type_for_value
函数
rest_get_best_type_for_value ( $value, $types )
- 参数
-
-
(mixed)
$value
The value to check.- Required: 是
-
(array)
$types
The list of possible types.- Required: 是
-
(mixed)
- 返回值
-
- (string) The best matching type, an empty string if no types match.
- 定义位置
-
-
wp-includes/rest-api.php
, line 1588
-
wp-includes/rest-api.php
- 引入
- 5.5.0
- 弃用
- –
获取一个值的最佳类型。
function rest_get_best_type_for_value( $value, $types ) { static $checks = array( 'array' => 'rest_is_array', 'object' => 'rest_is_object', 'integer' => 'rest_is_integer', 'number' => 'is_numeric', 'boolean' => 'rest_is_boolean', 'string' => 'is_string', 'null' => 'is_null', ); // Both arrays and objects allow empty strings to be converted to their types. // But the best answer for this type is a string. if ( '' === $value && in_array( 'string', $types, true ) ) { return 'string'; } foreach ( $types as $type ) { if ( isset( $checks[ $type ] ) && $checks[ $type ]( $value ) ) { return $type; } } return ''; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。