Home  >  Article  >  Backend Development  >  What does intval mean in php

What does intval mean in php

青灯夜游
青灯夜游Original
2021-11-22 19:02:203817browse

In PHP, intval means to get the integer value of a variable. It is a function that can convert other types of variables into integer types; this function converts by using the specified base base (the default is decimal), Return the integer value of the variable, the syntax is "intval($var,$base)".

What does intval mean in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, the intval function can obtain the variable Integer value. (Generally, the intval function is used for data type conversion, which can convert a string into an integer type.)

intval() function returns the integer value of the variable var by using the specified base conversion (default is decimal) . intval() cannot be used with object, otherwise an E_NOTICE error will be generated and 1 will be returned.

Syntax:

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

Parameter description:

  • $var: The quantity value to be converted to integer.

  • #$base: The base used for conversion.

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

  • If the string includes "0x" ( or "0X"), use hexadecimal (hex); otherwise,

  • If the string starts with "0", use octal (octal); otherwise,

  • Decimal will be used.

Return value

  • Returns the integer value of var on success, and returns 0 on failure. An empty array returns 0, a non-empty array returns 1.

  • The maximum value depends on the operating system. The maximum signed integer range on 32-bit systems is -2147483648 to 2147483647. For example, on such a system, intval('1000000000000') would return 2147483647. On a 64-bit system, the maximum signed integer value is 9223372036854775807.

  • String may return 0, although it depends on the leftmost character of the string.

Example:

<?php
echo intval(42)."<br>";                      // 42
echo intval(4.2)."<br>";                     // 4
echo intval(&#39;42&#39;)."<br>";                    // 42
echo intval(&#39;+42&#39;)."<br>";                   // 42
echo intval(&#39;-42&#39;)."<br>";                   // -42
echo intval(042)."<br>";                     // 34
echo intval(&#39;042&#39;)."<br>";                   // 42
echo intval(1e10)."<br>";                    // 1410065408
echo intval(&#39;1e10&#39;)."<br>";                  // 1
echo intval(0x1A)."<br>";                    // 26
echo intval(42000000)."<br>";                // 42000000
echo intval(420000000000000000000)."<br>";   // 0
echo intval(&#39;420000000000000000000&#39;)."<br>"; // 2147483647
echo intval(42, 8)."<br>";                   // 42
echo intval(&#39;42&#39;, 8)."<br>";                 // 34
echo intval(array())."<br>";                 // 0
echo intval(array(&#39;foo&#39;, &#39;bar&#39;))."<br>";     // 1
?>

What does intval mean in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does intval mean in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn