PHP - Function array_diff()


Advertisements


Syntax

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

Definition and Usage

It compares array1 against array2 and returns the difference.

Parameters

Sr.No Parameter & Description
1

array1(Required)

It is the first array is the array that the others will be compared with.

2

array2(Required)

It is an array to be compared with the first array

3

array3(Optional)

It is an array to be compared with the first array

Return Values

It returns an array containing the differences.

Example

Try out following example −

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

This will produce the following result −

Array ( [1] => banana )

php_function_reference.htm

Advertisements