PHP intdiv() 函数

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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程