Home >Backend Development >PHP Tutorial >How to subtract two arrays in php
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; } ?>
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!