array_diff() function in php
0 2100
array_diff() function of PHP compares the values of two and more arrays and return the difference in the form of new array. It is an inbuilt function of PHP.
The resulting array contains the values of first array that are not matches to other arrays values.
Syntax
array_diff ($arr1,$arr2,.....,$arrN);
Here
$arr1,$arr2 and $rrN are arrays.
Example 1:
<?php $arr1=array("Mango","Orange","Pear","Banana","Apple"); $arr2=array("Mango","Banana","Apple"); $new_arr=array_diff($arr1,$arr2); echo "<pre>"; print_r($new_arr); ?>
Output:
Example 2:
<?php $arr1=array("Mango","Orange","Pear","Banana","Apple"); $arr2=array("Mango","Banana","Apple"); $arr3=array("Orange","Mango"); $new_arr=array_diff($arr1,$arr2,$arr3); echo "<pre>"; print_r($new_arr); ?>
Output:
Share:
Comments
Waiting for your comments