Home >Backend Development >PHP Tutorial >PHP method to find a specific value in a multi-dimensional array_php tips

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

WBOY
WBOYOriginal
2016-05-16 20:09:271129browse

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")
)
)

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;
}

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

Statement:
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