How Can We Help?
Example: I have array A with values and another array B. I need to remove the values in array A from the values in array B.
- Use the PHP function array_diff
- Description
- a
- Description
<?php $arrayA = array('one','two'); $arrayB = array('one','two','three','four','five'); $newArray = array_diff($arrayB,$arrayA); echo '<pre>'; print_r($newArray); echo '</pre>'; ?>
- The code example above will print the following:
Array ( [2] => three [3] => four [4] => five )
- Explanation:
- Array A values will be removed from array B
- The $newArray variable will contain the values of array B with values from array A removed