PHP - Function array_diff()


Advertisements


Syntax

array array_diff ( array $array1, array $array2 [, array $array3 ...] );

Definition and Usage

Compares array1 against array2 and returns the difference.

Parameters

Sr.No Parameter & Description
1

array1

Required. The first array is the array that the others will be compared with.

2

array2

Required. An array to be compared with the first array

3

array3

Optional. An array to be compared with the first array

Return Values

Returns an array containing the differences.

Example

Try out following example −

<?php
   $input_array1 = array("orange", "banana", "apple");
   $input_array2 = array("orange", "mango", "apple");
   
   print_r(array_diff($input_array1, $input_array2));
?> 

This will produce the following result −

Array ( [1] => banana )

php_function_reference.htm

Advertisements