复制php变量的性能影响 [英] Performance impact of copying php variables

查看:64
本文介绍了复制php变量的性能影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道复制非常大的 php 变量对性能的影响.例如说 $arr 是一个巨大的数组.如果我执行 $arr2 = $arr,这是一个深拷贝还是 $arr2 只是一个指向 $arr 的指针,就像在 Java 中一样?提前致谢.

Just wondering about the performance impact of copying very large php variables. For example say $arr is an enormous array. If I do $arr2 = $arr, is this a deep copy or is $arr2 merely a pointer to $arr like it is in Java? Thanks in advance.

推荐答案

$arr2 = $arr 创建一个深拷贝.但是真正的复制只有在 $arr2 被修改时才会发生——PHP 使用 copy-on-write.

$arr2 = $arr creates a deep copy. But the actual copying only happens when $arr2 is modified -- PHP utilizes copy-on-write.

如果你想要一个指针"而不是一个副本,使用 $arr2 =&$arr,这使得 $arr2 成为 $arr 的引用.

If you want a "pointer" instead of a copy, use $arr2 =& $arr, which makes $arr2 a reference to $arr.

这篇关于复制php变量的性能影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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