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