php数组中删除元素的实现代码
代码如下:
<?php $arr = array('a','b','c','d'); unset($arr[1]); print_r($arr); ?>
print_r($arr)之后,结果却不是那样的,最终结果是 Array ( [0] => a [2] => c [3] => d
那么怎么才能做到缺少的元素会被填补并且数组会被重新索引呢?答案是array_splice():
代码如下:
<?php $arr = array('a','b','c','d'); array_splice($arr,1,1); print_r($arr); // <span style="font-family: Simsun;font-size:16px; ">Array ( [0] => a [1] => c [2] => d )</span> ?>
相关推荐
Noneyes 2020-11-10
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23