PHP method to find a specific value in a multi-dimensional array_php tips

WBOY
Release: 2016-05-16 20:09:27
Original
1106 people have browsed it

The example in this article describes the method of finding a specific value in a multi-dimensional array in PHP. Share it with everyone for your reference. The details are as follows:

When I was working on a project recently, I needed to find whether a multi-dimensional array contained a specific key and its corresponding specific value, and clear the data, such as:

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

Copy after login

Hope to achieve the effect: delete the record with 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

I hope this article will be helpful to everyone’s PHP programming design.

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