Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <?php echo $session_id ?> and <?= $session_id ?>

Tags:

php

Is there any particular reason to use one over the other? I personally tend to use the latter, as it just seems to flow better to me.

like image 970
Glen Solsberry Avatar asked Jan 12 '09 19:01

Glen Solsberry


3 Answers

They do the same thing, the <?= is just called the short tag and is shorthand for <?php echo. You have to make sure the short tags are enabled to use the <?= notation.

like image 180
Brian Fisher Avatar answered Oct 20 '22 01:10

Brian Fisher


As far as I know, they are functionally equivalent except the second can be disabled in configurations so isn't as portable.

like image 22
Rob Prouse Avatar answered Oct 19 '22 23:10

Rob Prouse


short_open_tag boolean

Tells whether the short form ( ) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use inline. Otherwise, you can print it with PHP, for example: . Also if disabled, you must use the long form of the PHP open tag ( ).

Note: This directive also affects the shorthand

Source.

like image 36
ohnoes Avatar answered Oct 19 '22 23:10

ohnoes