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
  • 275,078
  • 51
  • 420
  • 480
Jared
  • 1,916
  • 4
  • 22
  • 42

6 Answers6

5

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

Femaref
  • 59,667
  • 7
  • 131
  • 173
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
  • 142,114
  • 39
  • 237
  • 299
3

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

Emil
  • 7,112
  • 17
  • 75
  • 132
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,238
  • 12
  • 51
  • 62
2

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

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

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

Stefan Gehrig
  • 80,936
  • 24
  • 154
  • 184
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,113
  • 7
  • 14