php 按指定元素值去除数组元素的实现方法_php技巧
May 17, 2016 am 09:14 AM按指定元素值去除数组元素
//去除值为"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
)

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

Which array element has the smallest sum of absolute differences?

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

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?

Python program to recursively linearly search elements in an array

How to find array elements using array_search function in PHP
