array_diff() function in php

array_diff() function in php

by Pooja Chikara

0 2474

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:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat