search
HomeBackend DevelopmentPHP ProblemHow to delete the same data in two arrays in php

php method to delete the same data in two arrays: first create a PHP sample file; then define two arrays with the same elements; then determine the same elements in the two arrays by traversing; finally, unset The function deletes elements with the same value.

How to delete the same data in two arrays in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

PHP deletes the same elements in two arrays

<?php
$invite1 = &#39;18,19,20,21,22&#39;;
$invite2 = &#39;18,19&#39;;
$a = explode(",",$invite1);
$b = explode(",",$invite2);
foreach ($a as $key=>$v1) {
foreach($b as $key2=>$v2){
if($v1==$v2){
unset($a[$key]);//删除$a数组同值元素
unset($b[$key2]);//删除$b数组同值元素
}
}
}
var_dump($a);
var_dump($b);
?>

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to delete the same data in two arrays in php. For more information, please follow other related articles on the PHP Chinese website!

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment