Is there a cleaner way to assign multiple strings to a single variable in php?
I current do like this
<?php
$myStr = '';
$myStr .= 'John';
$myStr .= '<br>';
$myStr .= 'Paul';
$myStr .= '<br>';
$myStr .= 'Ringo';
echo $myStr;
?>
I also use HEREDOC
. But are there other ways?
If you have to concatenate lot of data, it may be a good idea to use
arrays
. It's cleaner (not necessarily more memory efficient).It can be done by
array
andimplode()
like below