PHP type conversion function intval

Source: Internet
Author: User

PHPCode
$ Id = intval ($ _ Get ['id']);
Intval
(PHP 4, PHP 5)
Intval-get the integer value of a Variable
Description
Int intval (mixed $ var [, int $ base = 10])
Returns the integer value of VaR, using the specified base for the conversion (the default is base 10 ).
Parameters
VaR
The scalar value being converted to an integer
Base
The base for the conversion (default is base 10)
Return values
The integer value of VaR on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of-2147483648 to 2147483647. so for example on such a system, intval ('000000') will return 1000000000000. the maximum signed integer value for 64 bit systems is 9223372036854775807.
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
Examples
Copy code The Code is as follows: <? PHP
Echo intval (42); // 42
Echo intval (4.2); // 4
Echo intval ('42'); // 42
Echo intval ('+ 42'); // 42
Echo intval ('-42'); //-42
Echo intval (042); // 34
Echo intval ('042'); // 42
Echo intval (1e10); /// 1410065408
Echo intval ('1e10'); // 1
Echo intval (0x1a); // 26
Echo intval (42000000); // 42000000.
Echo intval (420000000000000000000); // 0
Echo intval ('000000'); // 420000000000000000000
Echo intval (42, 8); // 42
Echo intval ('42', 8); // 34
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.