belongs to collection: PHP Basic Programs
Given two numbers and we have to find their division in PHP.
To find an integer division of two numbers in PHP, we can use intdiv() function, it accepts dividend and divisor and returns the result as an integer.
Syntax:
intdiv(divident, divisor);
Example:
Input: $a = 10; $b = 3; Function call: intdiv($a, $b); Output: 3
Here we are finding the division using two ways 1) divident/divisor – the result is a float value and 2) intdiv(dividend, divisor) – the result is an integer value.
<?php $a = 10; $b = 3; //normal division $result1 = $a/$b; print("value of result1: $result1 \n"); print("var_dump: "); var_dump($result1); print("\n"); //using intdiv() function $result2 = intdiv($a, $b); print("value of result2: $result2 \n"); print("var_dump: "); var_dump($result2); print("\n"); ?>
Output
value of result1: 3.3333333333333 var_dump: float(3.3333333333333) value of result2: 3 var_dump: int(3)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
intdiv() example in PHP
Here we are finding the division using two ways 1) divident/divisor – the result is a float value and 2) intdiv(dividend, divisor) – the result is an integer value.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer