zoukankan      html  css  js  c++  java
  • PHP intval() 函数

    http://www.runoob.com/php/php-intval-function.html

    intval() 函数用于获取变量的整数值。

    intval() 函数通过使用指定的进制 base 转换(默认是十进制),返回变量 var 的 integer 数值。 intval() 不能用于 object,否则会产生 E_NOTICE 错误并返回 1。

    PHP 4, PHP 5, PHP 7

    语法

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

    参数说明:

    • $var:要转换成 integer 的数量值。
    • $base:转化所使用的进制。

    如果 base 是 0,通过检测 var 的格式来决定使用的进制:

    • 如果字符串包括了 "0x" (或 "0X") 的前缀,使用 16 进制 (hex);否则,
    • 如果字符串以 "0" 开始,使用 8 进制(octal);否则,
    • 将使用 10 进制 (decimal)。

    返回值

    成功时返回 var 的 integer 值,失败时返回 0。 空的 array 返回 0,非空的 array 返回 1。

    最大的值取决于操作系统。 32 位系统最大带符号的 integer 范围是 -2147483648 到 2147483647。举例,在这样的系统上, intval('1000000000000') 会返回 2147483647。64 位系统上,最大带符号的 integer 值是 9223372036854775807。

    字符串有可能返回 0,虽然取决于字符串最左侧的字符。

    实例

    实例

    <?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('420000000000000000000'); // 2147483647
    echo intval(42, 8);                   // 42   第二个数字,8不显示
    echo intval('42', 8);                 // 34  这里是八进制
    echo intval(array());                 // 0
    echo intval(array('foo', 'bar'));     // 1
    ?>
    
  • 相关阅读:
    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
    如何从vss中分离程序
    String or binary data would be truncated
    the pop3 service failed to retrieve authentication type and cannot continue
    The POP3 service failed to start because
    IIS Error he system cannot find the file specified _找不到页面
    pku2575Jolly Jumpers
    pku2940Wine Trading in Gergovia
    pku3219二项式系数
    pku1029false coin
  • 原文地址:https://www.cnblogs.com/lxwphp/p/15454049.html
Copyright © 2011-2022 走看看