Home > Backend Development > PHP Tutorial > How to subtract two arrays in php

How to subtract two arrays in php

墨辰丷
Release: 2023-03-31 15:24:02
Original
6347 people have browsed it

This article mainly introduces the method of subtracting two arrays in PHP. It involves the related skills of PHP operating arrays. It has certain reference value. Friends in need can refer to the following

Examples of this article Learn how to use PHP to subtract two arrays. The details are as follows:

This code passes in two arrays A and B and returns the result of A-B, that is, selecting the elements that exist in A but not in B

<?php
function RestaDeArrays($vectorA,$vectorB)
{
  $cantA=count($vectorA);
  $cantB=count($vectorB);
  $No_saca=0;
  for($i=0;$i<$cantA;$i++)
  {
    for($j=0;$j<$cantB;$j++)
    {
     if($vectorA[$i]==$vectorB[$j])
     $No_saca=1;
    }
   if($No_saca==0)
   $nuevo_array[]=$vectorA[$i];
   else
   $No_saca=0;
   }
   return $nuevo_array;
}
?>
Copy after login

Summary : The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

The addition, deletion, modification and query functions implemented by mysql in php

php operates dates and characters String methods

php methods for string operations

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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template