Thursday, 4 June 2015

Send two arrays and get an array with the operation A-B, elements on A that are not included on 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;
         }

?>

how to use it--->$result=RestaDeArrays($arrayA,$arrayB);

0 comments:

Post a Comment