PHP intdiv() 函数
intdiv() 是 PHP 中的数学函数,用于计算整数除法。它返回被除数除以除数的整数商。
语法
int intdiv ( int dividend , intdivisor)
参数 | 描述 | 必需/可选 |
---|---|---|
$dividend | 要被除的数字 | 必需 |
$divisor | 除以被除数的数字 | 必需 |
示例1
<?php
echo "Your Number is : (3,2)"."<br>";
echo var_dump(intdiv(3, 2))." : is Output value";
?>
输出:
Your Number is : (3,2)
int(1) : is Output value
示例2
<?php
echo "Your Number is : (-3,2)"."<br>";
echo var_dump(intdiv(-3,2))." : is Output value";
?>
输出:
Your Number is : (-3,2)
int(-1) : is Output value
示例3
<?php
echo "Your Number is : (3,-2)"."<br>";
echo var_dump(intdiv(3, -2))." : is Output value";
?>
输出:
Your Number is : (3,-2)
int(-1) : is Output value
示例4
<?php
echo "Your Number is : (-3,-2)"."<br>";
echo var_dump(intdiv(-3,-2))." : is Output value";
?>
输出:
Your Number is : (-3,-2)
int(1) : is Output value
示例5
<?php
echo "Your given value is : (PHP_INT_MAX, PHP_INT_MAX)"."<br>";
echo var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX))." : is your Output value";
?>
输出:
Your given value is : (PHP_INT_MAX, PHP_INT_MAX)
int(1) : is your Output value
示例6
<?php
echo "Your given value is : (PHP_INT_MIN, PHP_INT_MIN)"."<br>";
echo var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN))." : is your Output value";
?>
输出:
Your given value is : (PHP_INT_MIN, PHP_INT_MIN)
int(1) : is your Output value
示例7
<?php
echo "Your given value is : (PHP_INT_MIN, -1)"."<br>";
echo var_dump(intdiv(PHP_INT_MIN, -1))." : is your Output value";
?>
输出:
Your given value is : (PHP_INT_MIN, -1)
Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer
示例8
<?php
echo "Your given value is : (1,0)"."<br>";
echo var_dump(intdiv(1,0))." : is your Output value";
?>
输出:
Your given value is : (1,0)
Fatal error: Uncaught DivisionByZeroError: Division by zero