Using echo inside a function is very bad practice. It almost always only works for one specific situation and can therefore never be used again in other projects.
Furthermore, splitting up code inside functions (and better: classes) gives you more flexibility in what to do with certain data.
For instance, let's say I've got an array, which I want to print in an HTML ordered list, but only the first 40 characters. This would work:
PHP Code:
function makeListFromArray ($array)
{
echo '<ol>';
foreach ($array as $a)
{
echo '<li>' . substr($a, 0, 40) . '</li>';
}
echo '</ol>';
}
But that's not really flexible, is it? What if I want to print out the entire string in a different situation, should I write another function called "makeListFromArrayComplete()"? Or what if I wanted to print only 30 characters instead of 40, should I write a whole new function?
This is where the real power of functions lies. Instead of really modifying values or printing it out directly, we can divide functionality.
Also, we can save the return value of a function inside a variable and use it later. Remember this: separate responsibilities! 
And last but not least; in big applications a function's purpose is almost never to just output something. Most functions I write modify data and return this new data.
Bookmarks