Scholar Repository
Home>Manual>Computes the difference of arrays with additional index check, compares data by a callback function

# array_udiff_assoc

(PHP 5)

array_udiff_assocComputes the difference of arrays with additional index check, compares data by a callback function

### Description

array array_udiff_assoc ( array \$array1 , array \$array2 [, array \$ ... ], callback \$data_compare_func )

Computes the difference of arrays with additional index check, compares data by a callback function.

Note: Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_udiff_assoc(\$array1, \$array2, "some_comparison_func");.

### Parameters

array1

The first array.

array2

The second array.

data_compare_func

The callback comparison function.

The user supplied callback function is used for comparison. It must return 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.

### Return Values

array_udiff_assoc() returns an array containing all the values from array1 that are not present in any of the other arguments. Note that the keys are used in the comparison unlike array_diff() and array_udiff(). The comparison of arrays' data is performed by using an user-supplied callback. In this aspect the behaviour is opposite to the behaviour of array_diff_assoc() which uses internal function for comparison.

### Examples

Example #1 array_udiff_assoc() example

```<?phpclass cr {     private \$priv_member;     function cr(\$val)     {         \$this->priv_member = \$val;     }     static function comp_func_cr(\$a, \$b)     {         if (\$a->priv_member === \$b->priv_member) return 0;         return (\$a->priv_member > \$b->priv_member)? 1:-1;     } } \$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),);\$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1=> new cr(4), 2 => new cr(-15),); \$result = array_udiff_assoc(\$a, \$b, array("cr", "comp_func_cr"));print_r(\$result);?>```

The above example will output:

```Array
(
[0.1] => cr Object
(
[priv_member:private] => 9
)

[0.5] => cr Object
(
[priv_member:private] => 12
)

 => cr Object
(
[priv_member:private] => 23
)
)
```

In our example above you see the "1" => new cr(4) pair is present in both arrays and thus it is not in the output from the function.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7044239,"math_prob":0.9473372,"size":2057,"snap":"2021-31-2021-39","text_gpt3_token_len":547,"char_repetition_ratio":0.15635656,"word_repetition_ratio":0.13166144,"special_character_ratio":0.3130773,"punctuation_ratio":0.15844156,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97962904,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-28T07:14:48Z\",\"WARC-Record-ID\":\"<urn:uuid:6b8a6c26-bab3-45a5-a738-5e6ad999d25b>\",\"Content-Length\":\"17178\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:be3a747b-af07-4120-9819-d2d22d89b043>\",\"WARC-Concurrent-To\":\"<urn:uuid:349b3a08-dd91-4d71-988d-5038db34c688>\",\"WARC-IP-Address\":\"103.112.189.161\",\"WARC-Target-URI\":\"https://digilib.unikom.ac.id/man/php/function.array-udiff-assoc.html\",\"WARC-Payload-Digest\":\"sha1:U6JJWD7ARRANIWWV34K46SP5RO3BH7RV\",\"WARC-Block-Digest\":\"sha1:35ZEYMYPLJ7JHPBZNIHEUUSTRIZAXQIE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153531.10_warc_CC-MAIN-20210728060744-20210728090744-00328.warc.gz\"}"}