PHP implementation method to remove array elements according to specified element value_PHP tutorial

WBOY
Release: 2016-07-21 15:23:44
Original
987 people have browsed it

Remove array elements by specified element value

Copy code The code is as follows:

//Remove value The element of "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 removal:

Array
(
[a] => Dog
[c] => Horse
)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324435.htmlTechArticleRemove array elements according to the specified element value. Copy the code. The code is as follows: ?php //Remove elements with the value "Cat" $a=array("a"="Dog","b"="Cat","c"="Horse"); print_r($a); unset($a[array_search("Cat"...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!