Program to execute return statement in php with example. Using this program we can print the return statement using the function. The return statement in PHP 7 now supports Type Declarations.
Enabling the strict requirement, as with the type declaration for function arguments, will result in a “Fatal Error” if a type mismatch occurs. When declaring the function, add a colon ( : ) and the type right before the opening curly ( )bracket to declare a type for the function return.
Advantages of Function
A function is a piece of code that takes another input in the form of a parameter, processes it, and then returns a value. Many functions, such as fopen() and fread(), have already been encountered. Although these are built-in functions, PHP also allows you to construct your own. Here;s the sample method to execute the execute return statement in php with example.
Return Statement in PHP
The return keyword terminates a function and, if desired, uses the result of an expression as the function’s return value. When return is used outside of a function, it prevents PHP code from running in the file. The intended data types of the result that a function or a class method should return are specified in the return type declaration.
Declaration in PHP
The declare keyword gives a block of code an execution direction. The directive applies to the rest of the code in the file if the declared statement is not followed by a block. A user-defined function’s declaration begins with the word function, followed by the name of the function you want to write, parenthesis (), and lastly your function’s code enclosed in curly brackets.
Execute Return Statement in Php With Example
<?
php declare(strict_types=1);
function addNumbers(float $a, float $b) : float
{
return $a + $b;
}
echo addNumbers(5,3.6);
?>
Output:
8.6
Java Program to Sort Strings in an Alphabetical Order
Java Program to Calculate Sum and Average of an Array
Java Program To Calculate Electricity Bill
Hello World Program in Java Without Using a Semicolon
Java Program to Find Largest Number in an Array
Java Program to Find Second Largest Number in an Array