What are the potential issues with mixing return and echo statements in PHP functions?

Mixing return and echo statements in PHP functions can lead to unexpected behavior and errors. It is best practice to use either return or echo consistently within a function to ensure clarity and maintainability of the code. To solve this issue, refactor the function to only use return statements for returning values and use echo statements outside of the function to display output.

function calculateSum($num1, $num2) {
    $sum = $num1 + $num2;
    return $sum;
}

$result = calculateSum(5, 3);
echo $result;