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

查看:100
本文介绍了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天全站免登陆