Syntax
array array_diff_assoc( array $array1, array $array2 [, array $array3...] );
|
Definition and Usage
Compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are used in the comparision.
Paramters
Parameter | Description |
array1 | Required. The array to compare from |
array2 | Required. An array to be compared with the first array |
array3 | Optional. An array to be compared with the first array |
Return Values
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
$input_array1 = array( a=>"orange", b=>"mango", c=>"banana");
$input_array2 = array( a=>"orange", b=>"apple", c=>"banana");
print_r(array_diff_assoc($input_array1, $input_array2));
$input_array1 = array( a=>"orange", b=>mango", c=>"banana");
$input_array2 = array( a=>"banana", b=>"apple", c=>"orange");
print_r(array_diff_assoc($input_array1, $input_array2));
?>
|
This will produce following result:
Array ( [b] => mango )
Array ( [a] => orange [b] => mango [c] => banana )
No comments:
Post a Comment