How to learn PHP array

Source: Internet
Author: User
Tags arrays learn php

Definitions and usage

Array_diff_ukey () returns an array that contains the values of all the key names that appear in the array1 but do not appear in any other parameter array. Note that the association relationship remains unchanged. Unlike Array_diff (), comparisons are based on the key name rather than the value.

This comparison is done through the user-supplied callback function. If you think that the first argument is less than, equal to, or greater than the second parameter, you must return an integer less than 0, equal to zero, or greater than 0, respectively.

Grammar

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

Parameters

Describe

Array1 required. The first array to compare with the other arrays.

Array2 required. The array to compare with the first array.

Array3 Optional. The array to compare with the first array. can have multiple.

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

Example 1

<?php function MyFunction ($v 1, $v 2) {if ($v 1=== $v 2) {return 0;} if ($v 1> $v 2) {return 1;} else {return-1;}} $ A1=array (0=> "Dog",1=> "Cat",2=> "horse"); $a 2=array (3=> "Rat",1=> "Bird",5=> "monkey"); Print_r (Array_diff_ukey ($a 1, $a 2, "myfunction"));?>

Output:

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

Example 2

How to assign multiple arrays to this function:

<?php function MyFunction ($v 1, $v 2) {if ($v 1=== $v 2) {return 0;} if ($v 1> $v 2) {return 1;} else {return-1;}} $ A1=array (0=> "Dog",1=> "Cat",2=> "horse"); $a 2=array (3=> "Rat",1=> "Bird",5=> "monkey"); $a 3=array (6=> "Dog",7=> "donkey",0=> "horse"); Print_r (Array_diff_ukey ($a 1, $a 2, $a 3, "myfunction"));?>

Output:

Array ([2] => horse)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.