What is the role of the "return" statement in PHP functions and how can it be used effectively?
The "return" statement in PHP functions is used to send a value back from the function to the code that called it. This allows the function to perform a task and then pass the result back to the calling code. The "return" statement can be used to return a single value, an array, or even an object.
// Example of a function that calculates the square of a number and returns the result
function calculateSquare($num) {
$square = $num * $num;
return $square;
}
// Calling the function and storing the result in a variable
$result = calculateSquare(5);
echo $result; // Output: 25