Returning values

Returning values

In PHP, functions can return values using the return statement. When a function is executed and a return statement is encountered, the value specified in the return statement is returned to the calling code.

For example, consider the following function that adds two numbers and returns the result:

function add($a, $b) { $result = $a + $b; return $result; } When this function is called with two arguments, like so: add(2, 3), it will return the value 5. This value can then be assigned to a variable or used in any other way the calling code sees fit.

Apply for PHP Certification!

https://www.vskills.in/certification/certified-php-developer

Back to Tutorials

Function arguments – PHP
Treasury Management

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?