Friday, September 7, 2012

PHP Function array_diff_assoc()

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

ParameterDescription
array1Required. The array to compare from
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 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

Labels

AJAX (1) Answers (1) Apache (1) Array (16) bug (1) C (1) C++ (1) Calendar (1) Class (1) Commands (1) Cookies (2) Database (2) Date (7) Days (1) explode (1) File Upload (1) FILES (1) firewall (1) fix (1) Functions (26) GET (1) GMT (1) JavaScript (2) localhost (1) Mail (1) Menu (1) MYSQL (13) PERL (1) PHP (36) php.ini (1) POST (1) preg_match (1) Questions (1) Script (1) SMS (2) Solution (1) String (1) Time (5) Time Zone (1) Vista (1) Wamp Server (1) windows 7 (2) XML (1)

Popular Posts

Popular Posts