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

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
WBOYOriginal
2016-07-29 08:47:121067browse

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.

Statement:
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