Sunday, 25 August 2013

PHP Function array_diff()

Syntax

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

Definition and Usage

Compares array1 against array2 and returns the difference.

Paramters

ParameterDescription
array1Required. The first array is the array that the others will be compared with.
array2Required. An array to be compared with the first array
array3Optional. An array to be compared with the first array

Return Values

Returns an array containing the differennces.

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 following result:
Array ( [1] => banana )

No comments:

Post a Comment