array_diff() function in php
×


array_diff() function in php

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:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments