This is not an issue.
You are overthinking things.
This is an old question, but the problem with the logic presented here is it assumes that “More commands equals slower performance…” when—in terms of modern programming and modern systems—this is an utterly irrelevant issue. These concerns are only of concerns of someone who—for some reason—programs at an extremely low level in something like assembler and such,.
The reason why is there might be a slowdown… But nothing anyone would ever humanly be able to perceive. Such as a slowdown of such a small fraction of a second that the any effort you make to optimize that code would not result in anything worth anything.
That said, speed and performance should always be a concern when programming, but not in terms of how many of a command you use.
As someone who uses PHP with echo
statements, I would recommend that you organize your code for readability. A pile of echo
statements is simply hard to read and edit. Depending on your needs you should concatenate the contents of those echo
statements into a string that you then echo
later on.
Or—a nice technique I use—is to create an array of values I need to echo
and then run echo implode('', $some_array);
instead.
The benefit of an array over string concatenation is it’s naturally easier to understand that some_array[] = 'Hello!';
will be a new addition to that array where something like $some_string .= 'Hello!';
might seem simple but it might be confusing to debug when you have tons of concatenation happening.
But at the end of the day, clean code that is easy to read is more important to all involved than shaving fractions of a second off of a process. If you are a modern programmer, program with an eye towards readability as a first draft and then—if necessary—think about optimizing that code.