1

Can someone explain to me when <?= needs to be used or why this programmer would code this way? I'm working on creating a third party module for SPBAS and I nearly figured it out, I just don't know the significance of the two different options I've specified.

Thanks in advance.

Blender
  • 289,723
  • 53
  • 439
  • 496
Jared
  • 2,006
  • 4
  • 23
  • 43

6 Answers6

5

<?= functionhere(); ?> is a short hand for <?php echo functionhere(); ?>.

Femaref
  • 60,705
  • 7
  • 138
  • 176
3

what <?=something?> is the short form of doing <?php echo something; ?>

where as <? something; ?> does whatever something was supposed to do

edit: im generalizing something as any php call, function string, array, object etc..

Naftali
  • 144,921
  • 39
  • 244
  • 303
3

<?php functionhere(); ?> does not print out the results from the function, <?=functionhere(); ?> does.

Emil
  • 7,220
  • 17
  • 76
  • 135
3

This is a shortcut syntax to echo the variable that comes after it. It has the same effect as

<?php echo $variable; ?> 

or

<?php echo functionhere(); ?>

in your case.

<?php functionhere(); ?>

will not do anything. unless something is printed out inside the function

For this to work, short_open_tag has to be enabled

naiquevin
  • 7,588
  • 12
  • 53
  • 62
2

<?= functionhere(); ?> = <?php echo functionhere(); ?>

<? functionhere(); ?> = <?php functionhere(); ?>

They are called short tags and can be enabled via the PHP configuration.

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
0

They do the same thing. Only difference is <?php is proper syntax. One is short tag for echo - but it should not be used because if this function is turned off it will output your code. Thanks for the vote down.

Chris McClellan
  • 1,123
  • 7
  • 14