I sometimes download sample code like everyone else does to save time and not have to reinvent wheels
I just came across this after a pretty complex code function so the person who wrote it seems to know what they’re doing PHP wise:
<?php if (isset($menu)) { ?>
<?php echo $menu; ?>
<?php } ?>
Why would you not instead write:
<?php if (isset($menu)) { echo $menu; } ?>
Curious as to which is better and if so why?
in your first example, there is no need to close and then re-open the PHP tags, it can be done just as you provided in example 2.
The only reason you would need to close and then re open the tags is if you wish to print out some more HTML as well: