| 1 |
lars |
1 |
<?php
|
|
|
2 |
// +----------------------------------------------------------------------+
|
|
|
3 |
// | PHP Version 4 |
|
|
|
4 |
// +----------------------------------------------------------------------+
|
|
|
5 |
// | Copyright (c) 1997-2004 The PHP Group |
|
|
|
6 |
// +----------------------------------------------------------------------+
|
|
|
7 |
// | This source file is subject to version 3.0 of the PHP license, |
|
|
|
8 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
9 |
// | available at through the world-wide-web at |
|
|
|
10 |
// | http://www.php.net/license/3_0.txt. |
|
|
|
11 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
12 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
13 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
14 |
// +----------------------------------------------------------------------+
|
|
|
15 |
// | Authors: Aidan Lister <aidan@php.net> |
|
|
|
16 |
// +----------------------------------------------------------------------+
|
|
|
17 |
//
|
|
|
18 |
// $Id: array_uintersect_uassoc.php,v 1.12 2005/01/26 04:55:13 aidan Exp $
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Replace array_uintersect_uassoc()
|
|
|
23 |
*
|
|
|
24 |
* @category PHP
|
|
|
25 |
* @package PHP_Compat
|
|
|
26 |
* @link http://php.net/function.array_uintersect_uassoc
|
|
|
27 |
* @author Aidan Lister <aidan@php.net>
|
|
|
28 |
* @version $Revision: 1.12 $
|
|
|
29 |
* @since PHP 5
|
|
|
30 |
* @require PHP 4.0.6 (is_callable)
|
|
|
31 |
*/
|
|
|
32 |
if (!function_exists('array_uintersect_uassoc')) {
|
|
|
33 |
function array_uintersect_uassoc()
|
|
|
34 |
{
|
|
|
35 |
$args = func_get_args();
|
|
|
36 |
if (count($args) < 4) {
|
|
|
37 |
user_error('Wrong parameter count for array_uintersect_uassoc()',
|
|
|
38 |
E_USER_WARNING);
|
|
|
39 |
return;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
// Get key_compare_func
|
|
|
43 |
$key_compare_func = array_pop($args);
|
|
|
44 |
if (!is_callable($key_compare_func)) {
|
|
|
45 |
if (is_array($key_compare_func)) {
|
|
|
46 |
$key_compare_func = $key_compare_func[0] . '::' . $key_compare_func[1];
|
|
|
47 |
}
|
|
|
48 |
user_error('array_uintersect_uassoc() Not a valid callback ' .
|
|
|
49 |
$key_compare_func, E_USER_WARNING);
|
|
|
50 |
return;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// Get data_compare_func
|
|
|
54 |
$data_compare_func = array_pop($args);
|
|
|
55 |
if (!is_callable($data_compare_func)) {
|
|
|
56 |
if (is_array($data_compare_func)) {
|
|
|
57 |
$data_compare_func = $data_compare_func[0] . '::' . $data_compare_func[1];
|
|
|
58 |
}
|
|
|
59 |
user_error('array_uintersect_uassoc() Not a valid callback '
|
|
|
60 |
. $data_compare_func, E_USER_WARNING);
|
|
|
61 |
return;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Check arrays
|
|
|
65 |
$count = count($args);
|
|
|
66 |
for ($i = 0; $i !== $count; $i++) {
|
|
|
67 |
if (!is_array($args[$i])) {
|
|
|
68 |
user_error('array_uintersect_uassoc() Argument #' .
|
|
|
69 |
($i + 1) . ' is not an array', E_USER_WARNING);
|
|
|
70 |
return;
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
// Traverse values of the first array
|
|
|
75 |
$intersect = array ();
|
|
|
76 |
foreach ($args[0] as $key => $value) {
|
|
|
77 |
// Check against each array
|
|
|
78 |
for ($i = 1; $i < $count; $i++) {
|
|
|
79 |
// Traverse each element in current array
|
|
|
80 |
foreach ($args[$i] as $ckey => $cvalue) {
|
|
|
81 |
// Compare key and value
|
|
|
82 |
if (call_user_func($key_compare_func, $key, $ckey) === 0 &&
|
|
|
83 |
call_user_func($data_compare_func, $value, $cvalue) === 0)
|
|
|
84 |
{
|
|
|
85 |
|
|
|
86 |
$intersect[$key] = $value;
|
|
|
87 |
continue;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
return $intersect;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
?>
|