PHP method to find specified value in multidimensional array

*文
Release: 2023-03-18 18:10:01
Original
3653 people have browsed it

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

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!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!