Is '<?=' the same as 'echo'?

2019-06-21 03:59发布

问题:

I've found some page where people print strings on the web page with this:

<?= 'hello world'; ?>

Is this a faster way to print strings in one row of code or does it work different?

回答1:

Yes. This would work as echo, but it IS NOT RECOMMENDED and many servers have got this availability disabled. It's called "short tag"



回答2:

According to the documentation, the <?= ... ?> form is a shortcut for echo, so they should be the same from a performance perspective.



回答3:

It's not exactly the same as just echo, it's a shortcut syntax.

<?= 'hello world'; ?>

would be the same as:

<?php echo 'hello world'; ?>

The latter is recommended because short_open_tags might be disabled on your server.



标签: php echo