intval In Php

Admin   PHP   1535  2020-08-13 04:23:51


(PHP 4, PHP 5, PHP 7)

intval() - Gets the integer value of a variable


intval (mixed $ var [, int $ base = 10]): int

Returns the integer value of var, using the base specified for conversion (default is base 10). intval() should not be used on objects, because doing so will generate an E_NOTICE level error and return 1.

intval in php

intval in php


Scalar values ​​are converted to an integer


    Facility to convert


        If base is 0, the base used is determined by the format of var:

            if the string includes the prefix "0x" (or "0X"), the base is taken as 16 (hex); if not,
            if the string begins with "0", then the base is taken as 8 (octal); if not,
            The base is taken as 10 (decimal).

Return value

The integer value of var on success or 0 on failure. Empty array returns 0, non-empty array returns 1.

The maximum value depends on the system. 32-bit systems have a maximum signed integer range from -2147483648 to 2147483647. Therefore, for example on such a system, intval ('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.

The string will most likely return 0 although this depends on the leftmost characters of the string. The general rules of integer casting apply.


intval in php


echo intval(12);
=> 12

echo intval('12');
=> 12

echo intval('blogdev');
=> 0