PHP program to find integer division using intdiv() function

PHP program to find integer division using intdiv() function

PHP intdiv() function example: Here, we will figure out how to discover the integer division of two given numbers in PHP utilizing intdiv() function?

Given two numbers and we need to discover their division in PHP.

To discover an integer division of two numbers in PHP, we can utilize intdiv() function, it acknowledges profit and divisor and returns the outcome as an integer.

Syntax:

    intdiv(divident, divisor);

Example:

    Input:
    $a = 10;
    $b = 3;

    Function call:
    intdiv($a, $b);

    Output:
    3

intdiv() example in PHP

Here we are finding the division utilizing two different ways 1) dividend/divisor – the outcome is a buoy value and 2) intdiv(dividend, divisor) – the outcome 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)

Recent Posts

error: Alert: Content is protected!!