PHP Unset Array 值对其他索引的影响 [英] PHP Unset Array value effect on other indexes

查看:29
本文介绍了PHP Unset Array 值对其他索引的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP 循环,我有一个关于未设置如何影响数组键的问题.这个数组使用 PHP 指定的标准数字键,0, 1, 2, 3 etc....每当 unset() 在数组值上运行时,数组键是被打乱还是像以前一样维护?

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?

感谢您的宝贵时间.

推荐答案

键不会被重新排列或重新编号.unset() 键被简单地删除,其他键保持不变.

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 Unset Array 值对其他索引的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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