PHP program to find integer division using intdiv() function

PHP intdiv() function example: Here, we are going to learn how to find the integer division of two given numbers in PHP using intdiv() function?
Submitted by IncludeHelp, on April 06, 2019

PHP - Integer Division of Two Numbers

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

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)

PHP Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.