$arr = array('a','b','c','d');
unset($arr[1]);
print_r($arr);
?>
print_r($arr)之后,结果却不是那样的,最终结果是 Array ( [0] => a [2] => c [3] => d
那么怎么才能做到缺少的元素会被填补并且数组会被重新索引呢?答案是array_splice():
$arr = array('a','b','c','d');
array_splice($arr,1,1);
print_r($arr); // Array ( [0] => a [1] => c [2] => d )
?>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn