PHP中的++ $ i和$ i ++有什么区别?

编程入门 行业动态 更新时间:2024-10-25 18:30:39
本文介绍了PHP中的++ $ i和$ i ++有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

PHP中的++$i和$i++有什么区别?

What's the difference between ++$i and $i++ in PHP?

推荐答案

++$i是预递增的,而$i++是后递增的.

++$i is pre-increment whilst $i++ post-increment.

  • 预递增:先递增变量i,然后取消引用.
  • 后递增:取消引用,然后递增i
  • pre-increment: increment variable i first and then de-reference.
  • post-increment: de-reference and then increment i

利用PHP事实 允许您后递增($ i ++) 和预增量(++ $ i).含义 只要你不一样就一样 写类似$ j = $ i ++的东西, 但是预增量几乎是10% 更快,这意味着您应该 从后增量切换到预增量 有机会的时候 特别是在严密的循环中 特别是如果您对 微观优化!" - TuxRadar

"Take advantage of the fact that PHP allows you to post-increment ($i++) and pre-increment (++$i). The meaning is the same as long as you are not writing anything like $j = $i++, however pre-incrementing is almost 10% faster, which means that you should switch from post- to pre-incrementing when you have the opportunity, especially in tight loops and especially if you're pedantic about micro-optimisations!" - TuxRadar

为进一步澄清,PHP中的后增量已被记录为存储一个临时变量,该临时变量归因于这10%的开销(相对于前增量).

For further clarification, post-incrementation in PHP has been documented as storing a temporary variable which attributes to this 10% overhead vs. pre-incrementation.

更多推荐

PHP中的++ $ i和$ i ++有什么区别?

本文发布于:2023-07-29 09:01:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!