Home > Backend Development > PHP Tutorial > PHP implementation method to remove array elements according to specified element value_PHP tutorial

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:23:44
Original
1093 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"...
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 Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template