Home > Backend Development > PHP Tutorial > php实现在多维数组中查找特定value的方法_PHP

php实现在多维数组中查找特定value的方法_PHP

WBOY
Release: 2016-05-30 08:47:32
Original
775 people have browsed it

本文实例讲述了php实现在多维数组中查找特定value的方法。分享给大家供大家参考。具体如下:

最近做项目,需要从多维数组中查找是否含有特定的key和其对应特定的value,并清除该条数据,比如:

$arr = array(
//为了看的方便,数组表达形式不对
0=>array(id =>1,name =>"li")
1=>array(id =>2,name =>"na")
2=>array(id =>3,name =>"na")
)
)

Copy after login

希望达到效果:删除id为2的那一条记录:

public function searchArray($array,$key,$value){
foreach($array as $keyp=>$valuep){
if($valuep[$key]==$value){
unset($array[$keyp]);
}
}
return $array;
}

Copy after login

希望本文所述对大家的php程序设计有所帮助。

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template