Correct way to output this from a function

Hi,
so i’ve got a function to check beach water quality status and i was previously echoing out from the function which appears to be bad practice so i’ve switched to returning an array with the information.

My question is whether it is correct to output the below in the way i have done it.

> //let put this in an array
>     $warning_array['abnormal'] = '<div id="abnormal">';
>     $warning_array['abnormal'] .= '<div id="ab_start">';
>     $warning_array['abnormal'] .= 'Abnormal situation '.date('d M Y h:i', strtotime($ab_date_start)).' <a href="#waterquality">(i)</a>';
>     $warning_array['abnormal'] .= '</div>';
>     $warning_array['abnormal'] .= '<div id="ab_desc">';
>     $warning_array['abnormal'] .= $resultab[0]->item->comment;
>     $warning_array['abnormal'] .= '</div>';
>     
>     $warning_array['abnormal'] .= '</div>';

Is this correct or should i only be returning the comment and date as different array variables and building the <div> structures and classes on the page i want to output to?

thanks

My personal view is that you should do the latter - return the information from the function, and allow the calling code to decide how to display it. If/when you come to change the display layout, you don’t want to have to change the function as well.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.