Home  >  Article  >  Backend Development  >  PHP implements the method of subtracting two arrays, array subtraction_PHP tutorial

PHP implements the method of subtracting two arrays, array subtraction_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:56:551003browse

PHP implements the method of subtracting two arrays, array subtraction

The example in this article describes the technique of php implementing the subtraction operation of two arrays. Share it with everyone for your reference. 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

<&#63;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;
}
&#63;>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985263.htmlTechArticlephp method to implement subtraction operation on two arrays, array subtraction This article tells the example of php implementation on two arrays Techniques for performing subtraction operations. Share it with everyone for your reference. Specifically...
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