PHP取消设置数组值 [英] PHP Unset Array Value

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

问题描述

我用PHP循环的工作,我有关于如何取消设置影响数组键一个问题。该阵列使用由PHP分配标准的数字键, 0,1,2,3等等... 。每当未设置()运行在一个数组值时,数组键洗牌或者他们像以前一样保持?

I am working with a PHP loop, and I had one question regarding how unset affects the array keys. This array uses the standard numeric keys assigned by PHP, 0, 1, 2, 3 etc.... Whenever unset() runs on an array value, are the array keys shuffled or are they maintained as before?

感谢您的时间。

推荐答案

不打乱重新编号或钥匙。在未设置()键简单地去掉,其它保持不变。

The keys are not shuffled or renumbered. The unset() key is simply removed and the others remain.

$a = array(1,2,3,4,5);
unset($a[2]);
print_r($a);

Array
(
    [0] => 1
    [1] => 2
    [3] => 4
    [4] => 5
)

这篇关于PHP取消设置数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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