Home >Backend Development >PHP Tutorial >How to implement multi-dimensional array traversal and unset deletion in PHP
This article mainly introduces how to implement multi-dimensional array traversal and unset deletion in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
I am working on a project recently. I need to find out whether a specific key and its corresponding specific value are contained in a multi-dimensional array, and clear the data. For example:
$arr = array( //为了看的方便,数组表达形式不对 0=>array(id =>1,name =>"li") 1=>array(id =>2,name =>"na") 2=>array(id =>3,name =>"na") ) )
I hope to achieve the effect: delete the id as The record of 2:
public function searchArray($array,$key,$value){ foreach($array as $keyp=>$valuep){ if($valuep[$key]==$value){ unset($array[$keyp]); } } return $array; }
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Summary sharing of PHP processing session functions
Related usage methods of php cache output
How to operate database with php combined with session
The above is the detailed content of How to implement multi-dimensional array traversal and unset deletion in PHP. For more information, please follow other related articles on the PHP Chinese website!