Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference <?php echo '$test'; ?> and <?=$test?>

Tags:

php

What is the difference between

<?php echo '$test'; ?>

and

<?=$test?>

?

like image 657
Ck Yong Avatar asked Nov 30 '22 05:11

Ck Yong


2 Answers

The former outputs the literal string $test and the latter outputs the value $test.

like image 43
mpen Avatar answered Dec 01 '22 18:12

mpen


Assuming you really meant <?php echo $test; ?>, the two are effectively the same thing. The question is, how portable do you want to be. <?php ?> is supported just about anywhere that PHP is supported, however lots of admins disable <?= ?> syntax.

like image 200
Jordan S. Jones Avatar answered Dec 01 '22 20:12

Jordan S. Jones