Difference between php tags


Well I'm learning Laravel and I got a question following some tutorials.

At certain times, within the view the tag is used: <?php foreach($produtos as $p): ?> and when I'm going to get the data <?= $p->nome ?> .

Is there any difference between <?php and <?= ?


Yes there is.

The <?php tag is the default for PHP file opens unless Short Tag is enabled, which allows you to open PHP with <? (which may conflict with XML statements)

The <?= tag, on the other hand, is quite simple:

Note: This directive also affects the short form <?= prior to PHP > 5.4.0 , which is the same as <? echo . To use this abbreviation, short_open_tag must be active. Since PHP 5.4.0 , <?= is always available.

Instead of using <?php echo $variable; ?> just use <?=$variable?>

Like the code to be more clean and readable.

I should point out that this is not from Laravel as described in the question, but from PHP.


As I'm studying Laravel and stopped this issue of passing on values ​​to views recommend taking advantage and studying Blade

On the blade output variables just using:

{{ $variable }}

Which is equivalent to:

echo $variable;

Much simpler, right?

Scroll to Top