PHP echo function return value vs echo inside function

后端 未结 5 1974
一向
一向 2020-12-16 04:06

Typically, I\'ll write a function like so:

function alertClass($field,$full=false){
 global $formErrors;
 $html = $full ? \' class=\"alert\"\' : \' alert\';
         


        
5条回答
  •  失恋的感觉
    2020-12-16 04:43

    Using echo preculdes using the function to programmatically build some HTML for output later on, or for further processing.

    If in your case there's no downside to returning the HTML, I'd continue doing it. It adds flexibility.

提交回复
热议问题