Home > Backend Development > PHP Tutorial > How to implement multi-dimensional array traversal and unset deletion in PHP

How to implement multi-dimensional array traversal and unset deletion in PHP

墨辰丷
Release: 2023-03-30 16:32:01
Original
3795 people have browsed it

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")
)
)
Copy after login

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;
}
Copy after login

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!

Related labels:
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