清除PHP数组的价值的最佳方法 [英] Best way to clear a PHP array's values

查看:74
本文介绍了清除PHP数组的价值的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对于数组清除所有值更有效率?第一个需要我每次使用该函数的第二个例子的环

 的foreach($数组作为$ I => $值){
    未设置($数组[$ i]);
}

或者这

 的foreach($ blah_blah为$等等){
    $富=阵列();
    //做一点事
    $ foo的= NULL;
}


解决方案

使用未设置的,如果你需要数组以后只需再次实例化。

 未设置($ foo的);
$富=阵列();

Which is more efficient for clearing all values in an array? The first one would require me to use that function each time in the loop of the second example.

foreach ($array as $i => $value) {
    unset($array[$i]);
}

Or this

foreach($blah_blah as $blah) {
    $foo = array();
    //do something
    $foo = null;
}

解决方案

Use unset, if you need the array later on just instantiate it again.

unset($foo);
$foo = array();

这篇关于清除PHP数组的价值的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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