"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
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);
?>
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.