Typically, I'll write a function like so:
function alertClass($field,$full=false){
global $formErrors;
$html = $full ? ' class="alert"' : ' alert';
if (!empty($formErrors[$field])) return $html;
}
and then where I want the html to show I'll echo the return value of the function like so:
echo alertClass('somefield')
but today I was thinking why not just put the echo in the function instead of using it's return value? So instead of "return $html" it would be "echo $html"... Is there an advantage to one way or the other?
for example when you echo the text out of your function just like this...
function yourStatus(){
echo ' Done';
}
echo 'Status ='. yourStatus();
your output will look like this
"DoneStatus ="
instead of
"Status = Done"
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With