Home >Backend Development >PHP Tutorial >PHP implements a method to find a specific value in a multidimensional array, multidimensional value_PHP tutorial

PHP implements a method to find a specific value in a multidimensional array, multidimensional value_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:45:531065browse

PHP implements the method of finding a specific value in a multi-dimensional array. Multi-dimensional value

The example in this article describes how PHP implements the method of finding a specific value in a multi-dimensional array. 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1039183.htmlTechArticlephp implements the method of finding a specific value in a multi-dimensional array, multi-dimensional value. This example describes the implementation of php in a multi-dimensional array Method to find a specific value. Share it with everyone for your reference. Specifically...
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