When I use a foreach to add content to a string i always use $x .= 'content' but first I have the declare that variable $x = '' which seems like an extra line of code that isn’t needed. Is there a better way to do this?
Here’s a good example:
$options = array('Link 1', 'Link 2', 'Link 3')
$output = '';
foreach($options as $value) $output .= '<a href="#">' . $value . '</a>';
echo $output;
you could try a ternary operator, like below, but again, this is more code. Unless I’m mistaken there isn’t a ‘non’ declaration way.