PHP program to create a function to find the addition of two integer numbers

PHP program to create a function to find the addition of two integer numbers

Here, we are going to execute a PHP program/code to discover the total/expansion of two numbers utilizing a client characterized function.

Given two numbers and we need to discover their expansion/total in PHP utilizing a client characterized function.

PHP code:

<?php
//function definition
//this function will take two integer arguments
//and return the sum of them
function addTwoNumbers(int $x, int $y)
{
    return $x + $y;
}

//calling the function and printing the result
echo " sum of 10 and 25 : " . addTwoNumbers(10, 25);
echo "<br>";
echo " sum of 30 and -10: " . addTwoNumbers(30, -10);
echo "<br>";
?>

Output:

 sum of 10 and 25 : 35
 sum of 30 and -10: 20

Code Explanation:

The function works by utilizing the standard math activity of including two integers. At whatever point we have to call the function, we utilize the accompanying configuration addTwoNumbers (x, y); by supplanting the values of x and y with two legitimate integers, we get the subsequent total in the output.

Recent Posts

error: Alert: Content is protected!!