"Cat","c"=>"Horse"); print_r($a); unset($a[array_search("Cat",$a)]);//array_search("Cat",$">
时间:2021-07-01 10:21:17 帮助过:8人阅读
//去除值为"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);
?>
查看array_search用法
显示结果
去除前:
Array
(
[a] => Dog
[b] => Cat
[c] => Horse
)
去除后:
Array
(
[a] => Dog
[c] => Horse
)http://www.bkjia.com/PHPjc/324435.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324435.htmlTechArticle按指定元素值去除数组元素 代码如下:
?php //去除值为"Cat"的元素 $a=array("a"="Dog","b"="Cat","c"="Horse"); print_r($a); unset($a[array_search("Cat"...