intdiv()
是PHP的数学函数,用于计算整数除法。它返回被除数除以除数的整数商。
语法:
int intdiv ( int $dividend , int $divisor)
参数 | 说明 | 必须/可选 |
---|---|---|
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
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
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
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
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
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
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
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
Fatal error: Uncaught DivisionByZeroError: Division by zero