PHP type conversion function intval_php tips

Source: Internet
Author: User
PHP code
$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. Bit systems have a maximum signed integer range of-2147483648 to 2147483647. So to example on such a system, intval (' 1000000000000 ') would return 2147483647. The maximum signed integer value for the 9223372036854775807-bit systems is.
Strings'll most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
examples
Copy Code code as follows:

<?php
Echo intval (+);//The
Echo intval (4.2);//4
Echo I Ntval (' 42 ');
Echo intval (' +42 ');//
Echo intval (' -42 ');// -42
Echo intval (042);//%
Echo intval (' 04 2 ');
Echo intval (1E10);//1410065408
Echo intval (' 1e10 ');//1
Echo intval (0x1A);//%
Echo int Val (42000000); 42000000
Echo intval (420000000000000000000);//0
Echo intval (' 420000000000000000000 ');//2147483647
echo Intval (42, 8);
Echo intval (' 8 ');//?>

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.