You probably know this, but number 2 is only true if the return is executed.
return (’hello’);
return(’goodbye’);
Will result in only ’hello’ being output.
Return in a snippet ends the snippet immediately (as does exit() or die() ) and nothing more is executed within the snippet.
Look closely at Doze’s example above it provides an excellent way of doing things in a snippet. If you use $output and then contcatenate your desired output to it with .= and then just have one return($output) statement in your snippet (never using echo or print), it will make your life *way* easier in the long run.
If your snippet is at all complicated, you’ll also want to look into using $modx->setPlaceholder() and putting placeholders in a template chunk.
That way you can set your snippet’s output to various placeholders anywhere in the snippet with no concerns about order or formatting. Then you just "return" the contents of the template chunk.
return($modx->getChunk('chunkName'))
and MODx does the rest for you by replacing the placeholders in the template with the values you’ve set before the page is sent to the browser.