I have three-rows code:
echo '<div>'; for ($i=1; $i<=4; $i++) echo $i; echo '</div>'; Is there any syntax or function let me rewrite above code in only ONE row, for example:
echo '<div>'.(for...).'</div>'; //error Thanks
I have three-rows code:
echo '<div>'; for ($i=1; $i<=4; $i++) echo $i; echo '</div>'; Is there any syntax or function let me rewrite above code in only ONE row, for example:
echo '<div>'.(for...).'</div>'; //error Thanks
While readability is completely personal opinion, there are "common" methods, guidelines, and coding standards which are used by a lot of developers.
And while you don't need to adhere to them, it is always up to you or the company you work for, some of these "ways" are just common sense regardless of your personal choice.
Even if there was a way to do it, why would you want to?
How far do you want to go mixing things together for supposed readability?
echo and a loop are completely different things, and should remain separate.
In answer to your question, no, it is not possible because PHP needs to differentiate between different "things" - functions, echo statements, variable declaration and usage, etc.
The only things you can "mix" are things which PHP allows to be together, like having a variable in a function parenthesis (function($someVar)).
The only thing you could do (and again this has no point, but your choice) is to put it all on one line, like so:
echo '<div>'; for ($i=1; $i<=4; $i++) { echo $i; } echo '</div>'; But that looks terrible.
I want to quickly see different things - "ah an echo, it prints out XYZ", then I want to see a loop separately so I can see easily what the loop is doing.
Yes its possible, no you dont want to do it:
echo '<div>' . implode('', array_keys(array_fill(1,4,0))) . '</div>';