absint( mixed $maybeint )

Convert a value to non-negative integer.


Description Description


Parameters Parameters

$maybeint

(mixed) (Required) Data you wish to have converted to a non-negative integer.


Top ↑

Return Return

(int) A non-negative integer.


Top ↑

Source Source

File: wp-includes/functions.php

4283
4284
4285
function absint( $maybeint ) {
    return abs( intval( $maybeint ) );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.

Top ↑

More Information More Information

Synonym of abs( intval( $foo ) );



Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Drew Jaynes

    When passing a negative integer, you’ll get the non-negative, absolute value. Passing a non-int string returns 0, but passing -10, returns 10:

    1
    2
    3
    echo absint( 'number' );        // 0
    echo absint( 10 );              // 10
    echo absint( -10 );             // 10
  2. Skip to note 2 content
    Contributed by MA Vinoth Kumar

    When passing float, it will return integer value

    1
    2
    3
    4
    5
    6
    echo absint(20.33);            // 20
    echo absint(-20.33);           // 20
    echo absint(false);            // 0
    echo absint(true);             // 1
    echo absint(array(10,20,30))   // 1
    echo absint(NULL)              // 0

You must log in before being able to contribute a note or feedback.