Home  >  Article  >  php教程  >  php unset删除数组指定元素方法代码

php unset删除数组指定元素方法代码

WBOY
WBOYOriginal
2016-06-08 17:25:411052browse
<script>ec(2);</script>

删除指定数组下标元素我们利用unset函数来实现,下在看看关于unset语法
void unset ( mixed var [, mixed var [, ...]])

unset() 销毁指定的变量。注意在 php教程 3 中,unset() 将返回 true(实际上是整型值 1

 

$array = array(1=>'1',2=>'2',3=>'3',4=>'5',5=>'6');
print_r( $array );



array
(
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 5
    [5] => 6
)

unset( $array[2]);
print_r($array);

array
(
    [1] => 1
    [3] => 3
    [4] => 5
    [5] => 6
)


本站原创,转载注明来源http://www.111cn.net 否则必究

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