>  기사  >  백엔드 개발  >  PHP intdiv() 함수

PHP intdiv() 함수

王林
王林앞으로
2023-09-18 19:05:111748검색

PHP intdiv() 函数

Definition and Usage

intdiv() 함수는 두 정수 매개변수의 정수 몫을 반환합니다. i Syntax

intdiv ( int $x , int $y ) : int

Parameters

Sr. 이 매개변수는 나누기 표현식

반환 값

PHP intdiv() 함수는 x를 로 나눈 정수 몫을 반환합니다. 두 인수가 모두 양수이거나 두 인수가 모두 음수인 경우 반환 값은 양수입니다. PHP 버전이 기능은 PHP 버전 4.x, PHP 5.x 및 PHP 7.x에서 사용할 수 있습니다. Example 라이브 데모ExampleLive DemonstrationIn 다음 예에서는 분자나 분모가 음수이므로 intdiv() 함수는 음수를 반환합니다. -Live DemonstrationThe 다음 예에서 분모는 0입니다. DivisionByZeroError 예외가 발생합니다. -1−
y
다음 예에서는 분자가 분모 <인 경우 intdiv() 함수가 0
<?php
   $x=10;
   $y=3;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
   $r=intdiv($y, $x);
   echo "intdiv(" . $y . "," . $x . ") = " . $r;
?>
Output

을 반환하여 다음 결과를 생성함을 보여줍니다. −

intdiv(10,3) = 3
intdiv(3,10) = 0

<?php
   $x=10;
   $y=3;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
   $x=10;
   $y=-3;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
   $x=-10;
   $y=3;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
   $x=-10;
   $y=-3;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r ;
?>
output이렇게 하면 다음과 같은 결과가 생성됩니다. −

intdiv(10,3) = 3
intdiv(10,-3) = -3
intdiv(-10,3) = -3
intdiv(-10,-3) = 3

Example

<?php
   $x=10;
   $y=0;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
?>

Output

이 결과는 다음과 같습니다−

PHP Fatal error: Uncaught DivisionByZeroError: Division by zero
Example Live Demonstration

두 매개변수의 소수 부분은 무시되고 intdiv() 함수는 정수 부분 -

<?php
   $x=2.90;
   $y=1.90;
   $r=intdiv($x, $y);
   echo "intdiv(" . $x . "," . $y . ") = " . $r . "</p><p>";
?>

Output

이 결과는 다음과 같습니다 −

intdiv(2.9,1.9) = 2

위 내용은 PHP intdiv() 함수의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제