这是我不久前需要澄清的事情。在 PHP 5.3+ 中,我想问这是否可以提高非常大数组结果的性能?你有什么方法可以证明吗?
$synonyms = & MobyThesaurus::GetSynonyms("check");
注意与号(通过引用,而不是通过值)。
这是我不久前需要澄清的事情。在 PHP 5.3+ 中,我想问这是否可以提高非常大数组结果的性能?你有什么方法可以证明吗?
$synonyms = & MobyThesaurus::GetSynonyms("check");
注意与号(通过引用,而不是通过值)。
PHP uses copy-on-write behind the scenes. Meaning, values are only copied when they're altered. Until then there's no copying going on and $synonyms
basically acts as a reference anyway. If you're only ever reading from the array, there should be no difference in performance.
Once you are writing to the array, it does make quite a bit of difference in functionality whether the variable is a reference or not. Don't use references unless you mean to, or you may introduce funky side effects into your app.
There are a many optimizations going on behind the scenes, don't expect to be able to optimize it any more with such "tricks". PHP is the wrong language for being clever with pointer/reference acrobatics. :-)