Shorthand For Loop in PHP -
i have three-rows code:
echo '<div>'; ($i=1; $i<=4; $i++) echo $i; echo '</div>';
is there syntax or function let me rewrite above code in 1 row, example:
echo '<div>'.(for...).'</div>'; //error
thanks
while readability personal opinion, there "common" methods, guidelines, , coding standards used lot of developers.
and while don't need adhere them, or company work for, of these "ways" common sense regardless of personal choice.
even if there way it, why want to?
how far want go mixing things supposed readability?
echo
, loop
different things, , should remain separate.
answer
in answer question, no, not possible because php needs differentiate between different "things" - functions, echo statements, variable declaration , usage, etc.
things can "mix" things php allows together, having variable in function parenthesis (function($somevar)
).
the thing (and again has no point, choice) put on 1 line, so:
echo '<div>'; ($i=1; $i<=4; $i++) { echo $i; } echo '</div>';
but looks terrible.
want quickly see different things - "ah echo, prints out xyz", want see loop separately can see loop doing.
Comments
Post a Comment