【发布时间】:2010-08-30 16:41:42
【问题描述】:
通常,我会写一个这样的函数:
function alertClass($field,$full=false){
global $formErrors;
$html = $full ? ' class="alert"' : ' alert';
if (!empty($formErrors[$field])) return $html;
}
然后我希望 html 显示在哪里,我会像这样回显函数的返回值:
echo alertClass('somefield')
但是今天我在想为什么不把 echo 放在函数中而不是使用它的返回值呢? 所以不是“return $html”而是“echo $html”...... 一种方式或另一种方式有优势吗?
【问题讨论】:
标签: php