Home Backend Development PHP Tutorial php 按指定元素值去除数组元素的实现方法_php技巧

php 按指定元素值去除数组元素的实现方法_php技巧

May 17, 2016 am 09:14 AM
array elements

按指定元素值去除数组元素

复制代码 代码如下:

//去除值为"Cat"的元素
$a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
print_r($a);
unset($a[array_search("Cat",$a)]);//array_search("Cat",$a)按元素值返回键名。去除后保持索引
print_r($a);
?>

查看array_search用法

显示结果

去除前:
Array
(
[a] => Dog
[b] => Cat
[c] => Horse
)

去除后:

Array
(
[a] => Dog
[c] => Horse
)
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to find the maximum and minimum value of array elements in Java How to find the maximum and minimum value of array elements in Java Oct 08, 2023 am 09:44 AM

How to find the maximum and minimum value of array elements in Java

Which array element has the smallest sum of absolute differences? Which array element has the smallest sum of absolute differences? Aug 29, 2023 am 10:09 AM

Which array element has the smallest sum of absolute differences?

How to use implode function to concatenate array elements into string in PHP How to use implode function to concatenate array elements into string in PHP Jun 26, 2023 pm 02:02 PM

How to use implode function to concatenate array elements into string in PHP

Concatenate array elements into a delimited string using PHP's implode() function Concatenate array elements into a delimited string using PHP's implode() function Nov 04, 2023 pm 02:37 PM

Concatenate array elements into a delimited string using PHP's implode() function

Get the element keys in an array using the PHP array_keys() function Get the element keys in an array using the PHP array_keys() function Jun 27, 2023 am 08:54 AM

Get the element keys in an array using the PHP array_keys() function

In C language, what are the array elements that appear multiple times? In C language, what are the array elements that appear multiple times? Sep 05, 2023 am 09:05 AM

In C language, what are the array elements that appear multiple times?

Python program to recursively linearly search elements in an array Python program to recursively linearly search elements in an array Aug 20, 2023 pm 11:22 PM

Python program to recursively linearly search elements in an array

How to find array elements using array_search function in PHP How to find array elements using array_search function in PHP Jun 26, 2023 pm 12:48 PM

How to find array elements using array_search function in PHP

See all articles