PHP - Function array_diff_assoc()


Advertisements


Syntax

array array_diff_assoc( 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 an array to compare from

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 all the values from array1 that are not present in any of the other arrays with the same keys.

Example

Try out following example −

<?php
   $input1 = array( "a"=>"orange", "b"=>"mango", "c"=>"banana");
   $input2 = array( "a"=>"orange", "b"=>"apple", "c"=>"banana");
   print_r(array_diff_assoc($input1, $input2));
   
   $input1 = array( "a"=>"orange", "b"=>"mango", "c"=>"banana");
   $input2 = array( "a"=>"banana", "b"=>"apple", "c"=>"orange");
   print_r(array_diff_assoc($input1, $input2));
?> 

This will produce the following result −

Array ( [b] => mango )
Array ( [a] => orange [b] => mango [c] => banana )

php_function_reference.htm

Advertisements