Array Diff Function in PHP

In this article I explain the PHP array_diff function.
  • 1335

Introduction

The array_diff() function computes the difference of arrays and returns an array with the key and values from the first array, if value is not present in any of the other arrays.

Syntax

array_diff (array1, array2, array3,...............)

Parameter in array_diff function

Parameter Description
array1 It specifies an array, who is compare from others.
array2 It  specifies an array to compare against.
..................... It specifies more array to compare against.

Example of array_diff function

<?php

$array1=array("a" => "Apple", "Mango", "Banana", "Mango");

$array2 = array("b" => "Apple", "Raspberry", "Mango");

$result = array_diff($array1, $array2);

print_r($result);

?>

Output

array-diff-function-in-php.jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.