absint()
absint( mixed $maybeint )
将值转换为非负整数,也就是取绝对值。
Convert a value to non-negative integer.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$maybeint | (mixed) | 必需 | 要转换为非负整数的数据。 |
返回(Return)
(int)非负整数。
源码(Source)
function absint( $maybeint ) { return abs( intval( $maybeint ) ); } /** * Convert a value to non-negative integer. * * @since 2.5.0 * * @param mixed $maybeint Data you wish to have converted to a non-negative integer. * @return int A non-negative integer. */ function absint( $maybeint ) { return abs( intval( $maybeint ) ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.5.0 | wp-includes/functions.php:4659 | 120 | 0 |
笔记(Notes)
echo absint( 'number' ); // 0 echo absint( 10 ); // 10 echo absint( -10 ); // 10
- 传递负整数时,将得到非负的绝对值。
- 传递非int字符串将返回0,但传递-10将返回10:
- 传递float时,它将返回整数值
absint() 为WP2原创文章,链接:https://www.wp2.cn/functions/absint/