How can the return statement be effectively used in PHP functions to pass variables?

When using the return statement in PHP functions, you can pass variables by simply specifying the variable you want to return after the return keyword. This allows you to retrieve and use the value of the variable outside of the function where it was defined. By returning variables from functions, you can create more modular and reusable code.

// Example of using return statement to pass variables in PHP functions
function calculateSum($num1, $num2) {
    $sum = $num1 + $num2;
    return $sum;
}

// Call the function and store the returned value in a variable
$total = calculateSum(5, 3);

// Output the result
echo "The sum is: " . $total; // Output: The sum is: 8