php-Arrays函数-array_diff_ukey-用回调函数对键名比较计算数组的差集
array_diff_ukey() 函数 用回调函数对键名比较计算数组的差集
【功能】
该函数将返回一个数组,
该数组包含了所有在array1中但是不在其他任何参数数组中的键名的值。
注意关联关系保持不变。此比较是通过用户提供的回调函数进行的。
如果认为第一个参数小于、等于、或大于第二个参数时,必须返回
一个小于零、等于零,或大于零的整数
【使用范围】
php5 > 5.1.0
【使用】
array array_diff_ukey( array array1, array array2[,array...,callback key_compare_func] )
array1/必需/数组1
array2/必需/比较的数组 最少得有一个
array.../可选/用来比较的数组
key_compare_func.../必需/为用户提供作为比较标准的回调函数
【示例】
[php]
//定义回调函数
function key_compare_func( $key1, $key2 )
{
if( $key1 == $key2 )
return 0;
else if( $key1 > $key2 )
return 1;
else
return -1;
}
//分别定义两个数组
$array1 = array( "blue" => 1, "red" => 2, "green" => 3,"purple" => 4 );
$array2 = array( "green" => 5, "blue" => 6, "yellow" => 7,"cyan" => 8 );
print_r( array_diff_ukey( $array1, $array2, "key_compare_func" ) );
/*
Array
(
[red] => 2
[purple] => 4
)*/
摘自 zuodefeng的笔记

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.