WordPress at a glance

absint() WP 2.5.0

Convert a value to non-negative integer. Analog of abs( intval( $foo ) ).

No Hooks.

Return

Int. A non-negative integer.

Usage

absint( $maybeint );
$maybeint(mixed) (required)
Data you wish to have converted to a non-negative integer.

Examples

#1 Examples of how the function processes the transmitted data:

echo absint( 'number' ); // 0
echo absint(    0 );     // 0
echo absint(   10 );     // 10
echo absint(  -10 );     // 10
echo absint( '-10' );    // 10
echo absint(   10.5 );   // 10
echo absint(  '10.5' );  // 10

echo absint( 'str' );    // 0
echo absint( 'str-10' ); // 0
echo absint( '-10str' ); // 10
echo absint(  '10str' ); // 10

echo absint( true );  // 1
echo absint( false ); // 0

echo absint( array('12') ); // 1
echo absint( array() );     // 0

Code of absint: wp-includes/functions.php VER 5.0

<?php
function absint( $maybeint ) {
	return abs( intval( $maybeint ) );
}

Related Functions

From category: Formatting

No comments
    Hello, !     Log In . Register