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

How to learn PHP array_diff_ukey()_PHP tutorial

WBOY
Release: 2016-07-13 10:23:42
Original
977 people have browsed it

How to learn PHP array_diff_ukey()

Definition and usage

array_diff_ukey() returns an array containing the values ​​of all keys that appear in array1 but do not appear in any other parameter array. Note that the relationship remains unchanged. Unlike array_diff(), the comparison is based on key names rather than values.

This comparison is performed via a user-supplied callback function. If the first argument is considered less than, equal to, or greater than the second argument, an integer less than zero, equal to zero, or greater than zero must be returned, respectively.

Grammar

array_diff_ukey(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=>"Rat",1=> "Bird",5=>"Monkey"); print_r(array_diff_ukey($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=>"Rat",1=> "Bird",5=>"Monkey"); $a3=array(6=>"Dog",7=>"Donkey",0=>"Horse"); print_r(array_diff_ukey($a1, $a2,$a3,"myfunction")); ?>

Output:

Array ( [2] => Horse )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834958.htmlTechArticleHow to learn PHP array_diff_ukey() definition and usage array_diff_ukey() returns an array that includes all occurrences in array1 in but not present in any other parameter array...
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