PHP中的++ $ i和$ i ++有什么区别? [英] What's the difference between ++$i and $i++ in PHP?

查看:76
本文介绍了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 ++有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆