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

WBOY
Release: 2016-07-13 09:45:53
Original
1027 people have browsed it

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

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.

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...
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