PHP array_diff_assoc

Last Updated: February 10, 2022

array_diff_assoc — Compare one array against several arrays and get the differences to the array

Compare the keys and values of two arrays.

Syntax

 array_diff_assoc(array $array, array ...$arrays): array

Parameters

Parameter Description
array Required. array to be compared
arrays Required. Arrays to compare against

Return Value

Return value is an array with difference value

Example

<?php
$array1 = array("One","2"=>"Two","Three",4=>"Four");
$array2 = array(1 =>"One","2"=>"Two","Three");
$result = array_diff_assoc($array1, $array2);
print_r($result);

?>

Output

Array ( 
	[0] => One 
	[4] => Four
 ) 
Test