Home > Backend Development > PHP Tutorial > Realize self-worth PHP implementation method to remove array elements according to specified element values

Realize self-worth PHP implementation method to remove array elements according to specified element values

WBOY
Release: 2016-07-29 08:47:12
Original
1069 people have browsed it

Remove array elements by specified element values

Copy code The code is as follows:


//Remove elements with value "Cat"
$a=array("a"=>"Dog ","b"=>"Cat","c"=>"Horse");
print_r($a);
unset($a[array_search("Cat",$a)]);// array_search("Cat",$a) returns the key name by element value. Keep index after removal
print_r($a);
?>


View array_search usage
Display results
Before removal:
Array
(
[a] => Dog
[b] => Cat
[ c] => Horse
)
After removing:
Array
(
[a] => Dog
[c] => Horse
)

The above introduces the implementation method of realizing self-worth in PHP by removing array elements according to specified element values, including the content of realizing self-worth. I hope it will be helpful to friends who are interested in PHP tutorials.

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