Home > php教程 > php手册 > body text

php 按指定元素值去除数组元素的实现方法

PHP中文网
Release: 2016-06-13 12:04:46
Original
1325 people have browsed it


按指定元素值去除数组元素

代码如下:

<?php 
//去除值为"Cat"的元素 
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse"); 
print_r($a); 
unset($a[array_search("Cat",$a)]);//array_search("Cat",$a)按元素值返回键名。去除后保持索引 
print_r($a); 
?>
Copy after login


查看array_search用法

显示结果

去除前:

Array 
( 
[a] => Dog 
[b] => Cat 
[c] => Horse 
)
Copy after login

去除后:

Array 
( 
[a] => Dog 
[c] => Horse 
)
Copy after login

以上就是php 按指定元素值去除数组元素的实现方法的内容,更多相关内容请关注PHP中文网(www.php.cn)!


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template