What are the potential pitfalls of using return instead of echo or print in PHP?

Using return instead of echo or print in PHP can cause unexpected behavior as return is meant to be used within functions to return a value, while echo and print are used to output data directly to the browser. To fix this issue, make sure to use echo or print when you want to display data to the user.

// Incorrect usage of return
function displayMessage() {
    return "Hello World!";
}

// Corrected code using echo
function displayMessage() {
    echo "Hello World!";
}