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.