Home > php教程 > php手册 > php实现在多维数组中查找特定value的方法,多维value

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

WBOY
Release: 2016-06-13 08:57:16
Original
984 people have browsed it

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

本文实例讲述了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程序设计有所帮助。

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