PHP删除数组中指定的元素

<?php 
//去除值为"Green"的元素 
$testarr=array("a"=>"Red","b"=>"Green","c"=>"Yellow"); 
print_r($testarr); 
unset($testarr[array_search("Green",$testarr)]);//array_search("Green",$testarr)按元素值返回键名。去除后保持索引 
print_r($testarr); 
?>

查看array_search用法
显示结果
去除前:
Array
(
[a] => Red
[b] => Greed
[c] => Yellow
)
去除后:
Array
(
[a] => Red
[c] => Yellow
)

原文地址:https://www.cnblogs.com/liuxgnu/p/3535421.html