search
Homephp教程php手册删除数组中某个值元素

删除数组中某个值元素

Jun 13, 2016 am 11:17 AM
arraydiffphpvalueelementfunctiondeleteuseExamplearray

删除数组中某个值元素本实例是要利用php array_diff函数来,删除数组中某个值元素哦,方法很简单用foreach再加array_diff函数就  

删除数组中某个值元素
本实例是要利用php教程 array_diff函数来,删除数组中某个值元素哦,方法很简单用foreach再加array_diff函数就
*/

$a1 = array(array('blue','red','www.bkjia.com'),array('black','pink','green'));
$a2 = array('aaa','pink','bbbb');
$str = 'red';
$a2[] = $str;
foreach($a1 as $key => $value)
{       
$a1[$key] = array_diff($value,$a2);
}
print_r($a1);


//更简单的做法

foreach (array_diff($a1, $a2) as $_key_1) {
        $arr_new[$_key_1] = $arr_1[$_key_1];
}


/*
结果如下:

array
(
    [0] => array
        (
            [0] => blue
            [2] => yellow
        )


    [1] => array
        (
            [0] => black
            [2] => green
        )


)

array_diff语法

array array_diff ( array $array1 , array $array2 [, array $ ... ] )
对比较array1和array2返回差异。
*/
$array1 = array("a" => "green", "php100.com", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

print_r($result);

/*
array
(
    [1] => blue
)


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 Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools