I have a very simple question for you guys. After deep researches, I've found nothing useful to get a good answer.
I just really like to know the way to write multiple instructions/commands in the same line, with PHP. Just to be clear, this:
<?php
if (true) {
echo "First,";
echo " second";
echo " and third.";
}
?>
shoud become this:
<?php
if (true)
echo "First," & echo " second" & echo " and third";
?>
So, the script above can execute three operations in one line of code. I tried to use the "&" sign to append more instructions in the same line and it seems it works... Is this the correct way to do what I want to do? May this cause any problems?
Thanks!
PS: the "echo" instruction is just as example (I know that you can merge strings just using the dot (.) sign
PHP puts no significance on a line break at all. All you need to do is remove the line break, everything else can stay exactly the same:
<?php if (true) { echo "First,"; echo " second"; echo " and third."; } ?>
The statements are already terminated and separated by ;
.
No. It's not correct. echo
is not a function, and is not something you can &
together like that. It does, however, support comma-separated "arguments", so something like
echo 'first', 'second', 'third';
is entirely possible and totally valid PHP code.
Even if the &
version was possible, you'd actually be LOSING efficiency, because you're doing 3 echo calls, and then trying to combine their non-existence return values. e.g. you'd be turning 3 operations into 5.