For cross-platform compatibility, use PHP_EOL instead of \n .
Using the example from the accepted answer above:
$array = array('this','is','another','way'); echo "<pre>".implode(PHP_EOL, $array)."</pre>";
If you write directly in HTML (this does not work with files), it is possible to use <br> as follows:
$array = array('this','is','third','way'); echo "<p>".implode(<br>, $array)."</p>";
source share