dozc1071
2009-01-12 19:33
采纳率: 100%
浏览 175
已采纳

<?php echo $ session_id?>和<?= $ session_id?>之间的区别

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.

图片转代码服务由CSDN问答提供 功能建议

是否有任何特别的理由使用一个而不是另一个? 我个人倾向于使用后者,因为它似乎对我来说更好。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • duan32342 2009-01-12 19:36
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongyi2083 2009-01-12 19:36

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

    评论
    解决 无用
    打赏 举报
  • dongyutan1703 2009-01-12 19:45

    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.

    评论
    解决 无用
    打赏 举报
  • dtpn60029 2009-01-12 20:14

    The shorthand is clearer. It says, with as few words possible:

    "Here, an expressions is echoed and nothing else is going on."

    评论
    解决 无用
    打赏 举报
  • douhanxujiuji6098 2009-01-12 21:57

    Short tags are disabled on a significant amount of php installation so I never use

    <?=$my_var?> // Bad Portability
    
    <?php echo $my_var; ?> // Good Portability!
    
    评论
    解决 无用
    打赏 举报
  • dongpeiwei8589 2009-02-10 17:10

    I would assume that <?php= $session_id; ?> works fine, and does not have the issue of portability.

    评论
    解决 无用
    打赏 举报
  • drcomwc134525 2010-03-19 10:43

    Just an addon question. I've read a few years ago that using <? and ?> is not recommended due to security issues. Is this correct?

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题