search
Homephp教程php手册php 按指定元素值去除数组元素的实现方法


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

代码如下:

<?php 
//去除值为"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 
)

以上就是php 按指定元素值去除数组元素的实现方法的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.