w3resource

PHP: array_diff_uassoc() function

PHP: Compares an array against another and returns the difference

The array_diff_uassoc() function is used to compare two or more arrays with an additional user supplied function. The function compares array1 against array2 and returns the difference. Unlike array_diff() the array keys are used in the comparison.

Version:

(PHP 4 and above)

Syntax:

array_diff_uassoc(array1, array2, array3,.....user-defined-function)

Parameter:

Name Description Required /
Optional
Type
array1 The specified array which will be compared with other arrays. Required Array
array2 Compared with the first array. Required Array
array3 Compared with the first array. Optional Array
user-defined-function The specified callback function. The function returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. Required -

Return value:

An array containing all the entries from array1 that are not present in any of the other arrays i.e. array2, array3.

Value Type: Array

Example:

<?php
function user_key_compare_func($x, $y)
{
if ($x === $y) 
{
return 0;
}
return ($x > $y)? 1:-1;
}
$array1 = array('Math'=>77, 20, 'Geography'=>89, 30, 'Language'=>67);
$array2 = array('Math'=>77, 'science'=>91 ,20, 'History'=>71);
$diff_result = array_diff_uassoc($array1, $array2, "user_key_compare_func");
print_r($diff_result);
?> 

Output:

Array([Geography]=>89[1]=>30[Language]=>67)

Pictorial Presentation:

php function reference: array_diff_uassoc() function

View the example in the browser

Practice here online:

See also

PHP Function Reference

Previous:array_diff_key
Next: array_diff_ukey



PHP: Tips of the Day

Convert HTML + CSS to PDF

Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2019. Online alternatives are better today at this than they were back then.

Here are some online services that you can use:

  • PDFShift
  • Restpack
  • PDF Layer
  • DocRaptor
  • HTMLPDFAPI
  • HTML to PDF Rocket

Have a look at PrinceXML.

It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since youalso need to take into account that the alternative solutions will require you to setup a dedicated server with the right software).

Ref : https://bit.ly/384yytr