Q:

PHP program to find integer division using intdiv() function

belongs to collection: PHP Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

<?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)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP program to handle modulo by zero exception... >>
<< PHP code to reverse an integer number...