Home > Backend Development > PHP Tutorial > How to learn PHP array_diff_uassoc()_PHP tutorial

How to learn PHP array_diff_uassoc()_PHP tutorial

WBOY
Release: 2016-07-13 10:23:44
Original
1099 people have browsed it

How to learn PHP array_diff_uassoc()

Definition and usage

The array_diff_uassoc() function uses a user-defined callback function to do index checking to calculate the difference between two or more arrays. Returns an array containing the values ​​in array1 but not in any of the other argument arrays.

Note that unlike the array_diff() function, key names are also compared.

The parameter function is a user-defined function used to compare two arrays. The function must take two parameters - namely, the two key names to be compared. So the behavior is exactly opposite to the function array_diff_assoc(), which uses an internal function for comparison.

The key names in the returned array remain unchanged.

Grammar

array_diff_uassoc(array1,array2,array3...,function)

Parameters

Description

array1 required. The first array to compare with other arrays.

array2 required. The array to compare to the first array.

array3 is optional. The array to compare to the first array. There can be multiple.

function required. The name of the user-defined function.

Example 1

$v2) { return 1; } else { return -1 ; } } $a1=array(0=>"Dog",1=>"Cat",2=>"Horse"); $a2=array(3=>"Dog",1=> "Cat",5=>"Horse"); print_r(array_diff_uassoc($a1,$a2,"myfunction")); ?>

Output:

Array ( [0] => Dog [2] => Horse )

Example 2

How to allocate multiple arrays to this function:

$v2) { return 1; } else { return -1 ; } } $a1=array(0=>"Dog",1=>"Cat",2=>"Horse"); $a2=array(3=>"Dog",1=> "Cat",5=>"Horse"); $a3=array(6=>"Bird",0=>"Dog",5=>"Horse"); print_r(array_diff_uassoc($a1, $a2,$a3,"myfunction")); ?>

Output:

Array ( [2] => Horse )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834957.htmlTechArticleHow to learn PHP array_diff_uassoc() definition and usage array_diff_uassoc() function uses user-defined callback function (callback) to do Index checking to calculate the difference between two or more arrays. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template