本文整理汇总了PHP中array_diff_uassoc函数的典型用法代码示例。如果您正苦于以下问题:PHP array_diff_uassoc函数的具体用法?PHP array_diff_uassoc怎么用?PHP array_diff_uassoc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_diff_uassoc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: a
function a()
{
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_uassoc($array1, $array2, "comp_func");
var_dump($result);
}
示例2: x
function x()
{
}
array_filter($a, 'x');
array_filter($a, 'Y::x');
array_filter($a, 'X::x');
array_filter($a, array($a, 'x2'));
class Y
{
static function x()
{
}
static function x2()
{
}
static function x3()
{
}
function z()
{
array_filter($a, array($this, 'x'));
}
}
$result = array_diff_uassoc($array1, $array2, $array3, $array4, 'Y2::x2');
$result = array_diff_uassoc($array1, $array2, $array3, $array4, 'X2::x2');
class Y2
{
static function x2()
{
}
}
示例3: array_diff_uassoc
* Description: Computes the difference of arrays with additional index check which is performed by a
* user supplied callback function
* Source code: ext/standard/array.c
*/
echo "*** Testing array_diff_uassoc() : error conditions ***\n";
//Initialize array
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$array3 = array("a" => "green", "red");
$array4 = array();
$extra_arg = array(1, 2, 3, 4);
function key_compare_func($a, $b)
{
if ($a === $b) {
return 0;
}
return $a > $b ? 1 : -1;
}
//Test array_diff_uassoc with one more than the expected number of arguments
echo "\n-- Testing array_diff_uassoc() function with more than expected no. of arguments --\n";
var_dump(array_diff_uassoc($array1, $array2, "key_compare_func", $extra_arg));
var_dump(array_diff_uassoc($array1, $array2, $array3, $array4, "key_compare_func", $extra_arg));
// Testing array_diff_uassoc with one less than the expected number of arguments
echo "\n-- Testing array_diff_uassoc() function with less than expected no. of arguments --\n";
var_dump(array_diff_uassoc($array1, $array2));
// Testing array_diff_uassoc with no arguments
echo "\n-- Testing array_diff_uassoc() function with no arguments --\n";
var_dump(array_diff_uassoc());
?>
===DONE===
示例4: array_diff_uassoc
<?php
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
* Description: Computes the difference of arrays with additional index check which is performed by a
* user supplied callback function
* Source code: ext/standard/array.c
*/
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
//Initialize variables
$arr_float = array(0 => 1.0, 1.0 => 2.0);
$arr_string_int = array('1', '2');
$arr_string_float = array('0' => '1.00', '1.00' => '2.00');
function key_compare_func($key1, $key2)
{
if ($key1 === $key2) {
return 0;
}
return $key1 > $key2 ? 1 : -1;
}
echo "\n-- Result of comparing floating points and strings containing integers --\n";
var_dump(array_diff_uassoc($arr_float, $arr_string_int, "key_compare_func"));
var_dump(array_diff_uassoc($arr_string_int, $arr_float, "key_compare_func"));
echo "\n-- Result of comparing floating points and strings containing floating point --\n";
var_dump(array_diff_uassoc($arr_float, $arr_string_float, "key_compare_func"));
var_dump(array_diff_uassoc($arr_string_float, $arr_float, "key_compare_func"));
?>
===DONE===
示例5: x
{
function x()
{
$a++;
}
}
class Yparent
{
static function x()
{
}
}
$result = array_diff_uassoc($array1, $array2, $array3, $array4, array('Y2', "parent::{$x4}"));
$result = array_diff_uassoc($array1, $array2, $array3, $array4, array('X2', "parent::{$x4}"));
$result = array_diff_uassoc($array1, $array2, $array3, $array4, array('Z2', "parent::{$x4}"));
$result = array_diff_uassoc($array1, $array2, $array3, $array4, array('Y2', 'x3'));
array_walk($array, array('X2', "parent::{$x4}"));
array_walk($array, array('Y2', "parent::{$x4}"));
array_walk($array, array('Z2', "parent::{$x4}"));
class Y2 extends Y2parent
{
static function x2()
{
}
}
class Y2parent
{
static function x3()
{
}
}
示例6: arrayDiffRecursive
/**
* Perform a recursive array diff
*
* Necessary starting in PHP 5.4; see https://bugs.php.net/bug.php?id=60278
*
* @param mixed $a
* @param mixed $b
* @return int
*/
public static function arrayDiffRecursive($a, $b)
{
if (is_array($a) && is_array($b)) {
return array_diff_uassoc($a, $b, sprintf('%s::arrayDiffRecursive', __CLASS__));
}
if ($a === $b) {
return 0;
}
return $a > $b ? 1 : -1;
}
示例7: file
<?php
$names = file(realpath($argv[1]), FILE_IGNORE_NEW_LINES);
echo "And the WINNER is... " . array_rand(array_flip(array_filter(array_reverse(array_column(array_chunk(array_intersect($names, array_replace($names, array_change_key_case(array_fill_keys($names, 'Rick Astley')))), (int) @array_pop(array_fill(array_reduce(array_keys($names), function ($c, $a) {
return $a;
}), array_unshift($names, 'Rick Astley'), '1 true love'))), array_sum(array_diff_ukey(array_intersect_key(array_diff_assoc(array_uintersect($names, array_intersect_assoc(array_uintersect_assoc($names, array_values($names), function ($a, $b) {
return $b > $a;
}), $names), function ($a, $b) use($names) {
return array_shift($names) > $b;
}), array()), array_uintersect_uassoc($names, array_udiff($names, array_diff($names, array_slice(array_merge(array_diff_uassoc(array_udiff_uassoc($names, $names, function ($a, $b) {
return $b > $a;
}, function ($a, $b) {
return $b > $a;
}), $names, function ($a, $b) {
return $a > $b;
}), array_combine($names, $names)), array_product($names), array_search(array_unique(array_count_values(array_merge_recursive($names, array_pad(array_replace_recursive($names, array_intersect_uassoc($names, $names, function ($a, $b) {
return $a > $b;
})), array_key_exists((int) array_walk($names, function ($v, $k) {
return $k;
}), $names), array_walk_recursive($names, function ($v, $k) {
return $k;
}))))), $names))), function ($a, $b) {
return $a > $b;
}), function ($a, $b) {
return $b > $a;
}, function ($a, $b) {
return $b > $a;
})), array_splice($names, array_multisort(array_map(function ($v) {
return $v;
}, array_intersect_ukey(array_diff_key($names, array_udiff_assoc($names, $names, function ($a, $b) {
return $a > $b;
示例8: diff_uassoc
/**
* (PHP 5)<br/>
* Computes the difference of arrays with additional index check which is performed by a user supplied callback function
* @link http://php.net/manual/en/function.array-diff-uassoc.php
* @param array $array2 <p>
* An array to compare against
* </p>
* @param array $_ [optional] <p>
* More arrays to compare against
* </p>
* @param callable $key_compare_func <p>
* The comparison function 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.
* </p>
* int<b>callback</b><b>mixed<i>a</i></b><b>mixed<i>b</i></b>
* @return array an array containing all the entries from
* <i>array1</i> that are not present in any of the other arrays.
*/
public function diff_uassoc(array $array2, array $_ = null, callable $key_compare_func)
{
// TODO: use func_get_args() for multiple arguments, like Arr($array)->function($v1, $v2, $v3)
return array_diff_uassoc($this->array, $array2, $key_compare_func);
}
示例9: pairDifference
/**
* Get key-value pairs which exist in one array but not in another,
* where both keys and values determine uniqueness.
*
* Returns an associative array containing all key-value pairs which
* exist in the first array but not in the second. Optionally provide
* comparison functions for the keys and values. String comparison is
* used by default.
*
* @param array $array1
* @param array $array2
* @param callable|null $key_cmp
* @param callable|null $value_cmp
* @return array
*/
public static function pairDifference($array1, $array2, $key_cmp = null, $value_cmp = null)
{
// Seriously, PHP? seriously?
if ($key_cmp === null) {
if ($value_cmp === null) {
return array_diff_assoc($array1, $array2);
} else {
return array_udiff_assoc($array1, $array2, $value_cmp);
}
} else {
if ($value_cmp === null) {
return array_diff_uassoc($array1, $array2, $key_cmp);
} else {
return array_udiff_uassoc($array1, $array2, $value_cmp, $key_cmp);
}
}
}
示例10: array_diff_uassoc
<?php
/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
* Description: Computes the difference of arrays with additional index check which is performed by a
* user supplied callback function
* Source code: ext/standard/array.c
*/
echo "*** Testing array_diff_uassoc() : usage variation ***\n";
// Initialise function arguments not being substituted (if any)
$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0);
$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF');
echo "\n-- Testing array_diff_key() function with float indexed array --\n";
var_dump(array_diff_uassoc($input_array, $boolean_indx_array, "strcasecmp"));
var_dump(array_diff_uassoc($boolean_indx_array, $input_array, "strcasecmp"));
?>
===DONE===
示例11: cmpUsed
<?php
function cmpUsed($a, $b)
{
return true;
}
function cmpUsedFullnspath($a, $b)
{
return true;
}
function cmpNotUsed($a, $b)
{
return true;
}
array_diff_uassoc(range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10), 'cmpUsed');
array_uintersect(range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10), '\\cmpUsedFullnspath');
array_udiff_assoc(range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10), '\\cmp\\b');
/*
function callableArguments ($a, Callable $b) { var_dump($b); }
Notuasort(range(1,10), 'cmpNot');
callableArguments(1, 'cmp3');
*/
示例12: array
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4, 18);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8, 9, 8);
var_dump(array_diff_key($array1, $array2));
?>
</div>
<h3><code>array</code> array_diff_uassoc(<code>array $array1, $array2 [, array $...], callable $key_compare_func</code>) <span class="badge">5+</span></h3>
<div><?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
var_dump(array_diff_uassoc($array1, $array2, function ($a, $b) {
echo "/ {$a} {$b} /";
if ($a === $b) {
return 0;
}
return $a > $b ? 1 : -1;
}));
?>
</div>
<h3><code>array</code> array_diff_ukey(<code>array $array1, $array2 [, array $...], callable $key_compare_func</code>) <span class="badge">5.1+</span></h3>
<div><?php
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_diff_ukey($array1, $array2, function ($k1, $k2) {
echo "/ {$k1} {$k2} /";
if ($k1 == $k2) {
示例13: array_diff_uassoc
/**
* @param HTArray $array2
* @param $key_compare_func
* @return $this
* @desc 通过用户提供的回调函数做索引检查来计算数组的差集。
*/
public function array_diff_uassoc(HTArray $array2, $key_compare_func)
{
$this->current = array_diff_uassoc($this->current, (array) $array2, $key_compare_func);
return $this;
}
示例14: set_exception_handler
<?php
set_exception_handler(function ($a1) {
});
array_filter($a, function ($a2) {
});
$result = array_diff_uassoc($array1, $array2, $array3, $array4, function ($a3) {
});
$result = array_diff_uassoc($array1, $array2, $array3, function ($a4) {
});
$result = array_diff_uassoc($array1, $array2, $array3, $array4, $array5, function ($a5) {
});
array_walk($array, function ($a6) {
});
print function ($a7) {
};
示例15: comp_func_cr
{
$this->priv_member = $val;
}
function comp_func_cr($a, $b)
{
if ($a->priv_member === $b->priv_member) {
return 0;
}
return $a->priv_member > $b->priv_member ? 1 : -1;
}
function comp_func_key($a, $b)
{
if ($a === $b) {
return 0;
}
return $a > $b ? 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));
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
print_r(array_udiff($a, $b, array("cr", "comp_func_cr")));
print_r(array_udiff_assoc($a, $b, array("cr", "comp_func_cr")));
print_r(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")));
print_r(array_diff_uassoc($array1, $array2, "key_compare_func"));
print "------------------------------------\n";
print_r(array_uintersect($a, $b, array("cr", "comp_func_cr")));
print_r(array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")));
print_r(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")));
print_r(array_intersect_uassoc($array1, $array2, "key_compare_func"));