tags:

views:

552

answers:

7
<?php

$a=1;

?>
<?=$a;?>

What does <?= mean exactly?

+20  A: 

It's a shorthand for this:

<?php echo $a; ?>

They're called short tags; see example #2 in the documentation.

Will Vousden
Please note that all servers do not support short tags as mentioned in an answer below. They require php.ini to have `short_open_tag = On`
cballou
+15  A: 

It's a shorthand for <?php echo $a; ?>.

This works only if the short_open_tag is enabled. There's by the way a rumour around that it's going to become deprecated in PHP6.

BalusC
Is that story true?
The rumour was around about a year ago IIRC. I recall that it was rebutted as not being true (just a misunderstanding/FUD). Alas I have no citation to back that up.
Iain Collins
I heard it too, but they will not be removed. Here is source: http://www.mail-archive.com/[email protected]/msg41845.html
Gordon
+2  A: 
<?=$a; ?>

is a shortcut for:

<?php echo $a; ?>
Inspire
+2  A: 

<?= $a ?> is the same as <? echo $a; ?>, just shorthand for convenience.

Jeffrey Aylesworth
+1  A: 

It's a shortcut for <?php echo $a; ?> if short_open_tags are enabled. Ref: http://php.net/manual/en/ini.core.php

kemp
+1  A: 

Since it wouldn't add any value to repeat that it means echo, I thought you'd like to see what means in PHP exactly:

Array
(
    [0] => Array
        (
            [0] => 368 // T_OPEN_TAG_WITH_ECHO
            [1] => <?=
            [2] => 1
        )
    [1] => Array
        (
            [0] => 309 // T_VARIABLE
            [1] => $a
            [2] => 1
        )
    [2] => ; // UNKNOWN <-- odd, isn't it
    [3] => Array
        (
            [0] => 369 // T_CLOSE_TAG
            [1] => ?>
            [2] => 1
        )
)

You can use this code to test it yourself:

$tokens = token_get_all('<?=$a;?>');
print_r($tokens);
foreach($tokens as $token){
    echo token_name((int) $token[0]), PHP_EOL;
}

From the List of Parser Tokens, here is what T_OPEN_TAG_WITH_ECHO links to.

Gordon
The token failed to tell me more details.
A: 
radiosilence