Home >Backend Development >PHP Tutorial >PHP method to find specified value in multidimensional array

PHP method to find specified value in multidimensional array

*文
*文Original
2017-12-28 15:47:403785browse

This article mainly introduces the method of PHP to find a specific value in a multi-dimensional array. The example analyzes the related techniques of PHP to implement multi-dimensional array traversal and unset deletion. I hope to be helpful. 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 specifics are as follows:

Recently working on a project, you need to find whether a specific key and its corresponding specific value are contained in a multi-dimensional array, 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;
}

Related recommendations:

Summary of PHP array sorting method

PHP array traversal foreach syntax structure and Example

PHP array splicing and reorganization

The above is the detailed content of PHP method to find specified value in multidimensional array. For more information, please follow other related articles on the PHP Chinese website!

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