Home  >  Article  >  Backend Development  >  php实现对两个数组进行减法操作的方法,数组减法_PHP教程

php实现对两个数组进行减法操作的方法,数组减法_PHP教程

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

php实现对两个数组进行减法操作的方法,数组减法

本文实例讲述了php实现对两个数组进行减法操作的技巧。分享给大家供大家参考。具体如下:

本代码传入两个数组A和B,返回A-B的结果,即挑选出存在于A,但不存在于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;>

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/985263.htmlTechArticlephp实现对两个数组进行减法操作的方法,数组减法 本文实例讲述了php实现对两个数组进行减法操作的技巧。分享给大家供大家参考。具体如...
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