andrey Wed Jul 21 17:17:56 2004 EDT
Added files:
/php-src/ext/standard/tests/array array_intersect_key.phpt
array_diff_key.phpt
Modified files:
/php-src NEWS
/php-src/ext/standard array.c php_array.h basic_functions.c
Log:
add array_:
intersect_key()
intersect_ukey()
diff_key()
diff_ukey()
The first two by a patch of Cristiano Duarte. The second two were
implemented in almost the same way except one small difference.
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1769&r2=1.1770&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1769 php-src/NEWS:1.1770
--- php-src/NEWS:1.1769 Wed Jul 21 00:38:47 2004
+++ php-src/NEWS Wed Jul 21 17:17:56 2004
@@ -5,6 +5,11 @@
- Fixed bug #29236 (memory error when wsdl-cache is enabled). (Dmitry)
- Fixed bug #29109 (SoapFault exception: [WSDL] Out of memory). (Dmitry)
- Fixed bug #29061 (soap extension segfaults). (Dmitry)
+- Added new functions :
+ . array_diff_key() (Andrey)
+ . array_diff_ukey() (Andrey)
+ . array_intersect_key() (Christiano Duarte)
+ . array_intersect_ukey() (Christiano Duarte)
- Added MDTM support to ftp_url_stat. (Sara)
- Added zlib stream filter suport. (Sara)
- Added bz2 stream filter support. (Sara)
http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.266&r2=1.267&ty=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.266 php-src/ext/standard/array.c:1.267
--- php-src/ext/standard/array.c:1.266 Sun Jul 11 17:15:04 2004
+++ php-src/ext/standard/array.c Wed Jul 21 17:17:56 2004
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.266 2004/07/11 21:15:04 andrey Exp $ */
+/* $Id: array.c,v 1.267 2004/07/21 21:17:56 andrey Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -77,6 +77,7 @@
#define DIFF_NORMAL 0
#define DIFF_ASSOC 1
+#define DIFF_KEY 2
#define DIFF_COMP_DATA_INTERNAL 0
#define DIFF_COMP_DATA_USER 1
#define DIFF_COMP_KEY_INTERNAL 0
@@ -84,6 +85,7 @@
#define INTERSECT_NORMAL 0
#define INTERSECT_ASSOC 1
+#define INTERSECT_KEY 2
#define INTERSECT_COMP_DATA_INTERNAL 0
#define INTERSECT_COMP_DATA_USER 1
#define INTERSECT_COMP_KEY_INTERNAL 0
@@ -2797,12 +2799,17 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type
is %d. This should never happen. Please report as a bug", data_compare_type);
return;
}
- } else if (behavior == INTERSECT_ASSOC) {
+ } else if ((behavior == INTERSECT_ASSOC)
+ ||(behavior == INTERSECT_KEY)) {
+ /*
+ INTERSECT_KEY is subset of INTERSECT_ASSOC. When having the
former
+ no comparison of the data is done (part of INTERSECT_ASSOC)
+ */
intersect_key_compare_func = array_key_compare;
if (data_compare_type == INTERSECT_COMP_DATA_INTERNAL
&&
key_compare_type == INTERSECT_COMP_KEY_INTERNAL) {
- /* array_intersect_assoc() */
+ /* array_intersect_assoc() or array_intersect_key() */
if (argc < 2) {
efree(args);
@@ -2833,7 +2840,7 @@
} else if (data_compare_type == INTERSECT_COMP_DATA_INTERNAL
&&
key_compare_type == INTERSECT_COMP_KEY_USER) {
- /* array_intersect_uassoc() */
+ /* array_intersect_uassoc() or array_intersect_ukey()
*/
if (argc < 3) {
efree(args);
@@ -2910,7 +2917,7 @@
*list = NULL;
if (behavior == INTERSECT_NORMAL) {
zend_qsort((void *) lists[i], hash->nNumOfElements,
sizeof(Bucket *), intersect_data_compare_func TSRMLS_CC);
- } else if (behavior == INTERSECT_ASSOC) {
+ } else if ((behavior == INTERSECT_ASSOC) || (behavior ==
INTERSECT_KEY)) {
zend_qsort((void *) lists[i], hash->nNumOfElements,
sizeof(Bucket *), intersect_key_compare_func TSRMLS_CC);
}
}
@@ -2926,7 +2933,8 @@
/* go through the lists and look for common values */
while (*ptrs[0]) {
- if (behavior == INTERSECT_ASSOC
+ if ((behavior == INTERSECT_ASSOC
+ || behavior == INTERSECT_KEY)
&&
key_compare_type == INTERSECT_COMP_KEY_USER) {
@@ -2938,12 +2946,18 @@
while (*ptrs[i] && (0 < (c =
intersect_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
- } else if (behavior == INTERSECT_ASSOC) {
+ } else if (behavior == INTERSECT_ASSOC || behavior ==
INTERSECT_KEY) {
while (*ptrs[i] && (0 < (c =
intersect_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
- if (!c && *ptrs[i]) { /* this means that ptrs[i] is
not NULL so we can compare */
- /* and "c==0" is from last operation */
+ if ((!c && *ptrs[i]) && (behavior == INTERSECT_ASSOC))
{
+ /*
+ this means that ptrs[i] is not NULL so
we can compare
+ and "c==0" is from last operation
+ in this branch of code we enter only
when INTERSECT_ASSOC
+ since when we have INTERSECT_KEY
compare of data is not
+ wanted.
+ */
if (data_compare_type ==
INTERSECT_COMP_DATA_USER) {
BG(user_compare_func_name) =
args[arr_argc];
}
@@ -2951,7 +2965,7 @@
c = 1;
if (key_compare_type ==
INTERSECT_COMP_KEY_USER) {
BG(user_compare_func_name) =
args[argc - 1];
- /* When KEY_USER the last
parameter is always the callback */
+ /* When KEY_USER, the last
parameter is always the callback */
}
/* we are going to the break */
} else {
@@ -2996,7 +3010,7 @@
if (0 <= intersect_data_compare_func(ptrs[0],
ptrs[i] TSRMLS_CC)) {
break;
}
- } else if (behavior == INTERSECT_ASSOC) {
+ } else if (behavior == INTERSECT_ASSOC || behavior ==
INTERSECT_KEY) {
/* no need of looping because indexes are
unique */
break;
}
@@ -3012,7 +3026,7 @@
if (intersect_data_compare_func(ptrs[0]-1,
ptrs[0] TSRMLS_CC)) {
break;
}
- } else if (behavior == INTERSECT_ASSOC) {
+ } else if (behavior == INTERSECT_ASSOC || behavior ==
INTERSECT_KEY) {
/* no need of looping because indexes are
unique */
break;
}
@@ -3032,6 +3046,23 @@
efree(args);
}
+/* {{{ proto array array_intersect_key(array arr1, array arr2 [, array ...], callback
data_compare_func)
+ Returns the entries of arr1 that have keys which are present in all the other
arguments. Kind of equivalent to array_diff(array_keys($arr1),
array_keys($arr2)[,array_keys(...)]). Equivalent of array_intersect_assoc() but does
not do compare of the data. */
+PHP_FUNCTION(array_intersect_key)
+{
+ php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_KEY,
+ INTERSECT_COMP_DATA_INTERNAL,
INTERSECT_COMP_KEY_INTERNAL);
+}
+
+/* {{{ proto array array_intersect_ukey(array arr1, array arr2 [, array ...],
callback key_compare_func)
+ Returns the entries of arr1 that have keys which are present in all the other
arguments. Kind of equivalent to array_diff(array_keys($arr1),
array_keys($arr2)[,array_keys(...)]). The comparison of the keys is performed by a
user supplied function. Equivalent of array_intersect_uassoc() but does not do compare
of the data. */
+PHP_FUNCTION(array_intersect_ukey)
+{
+ php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_KEY,
+ INTERSECT_COMP_DATA_INTERNAL, INTERSECT_COMP_KEY_USER);
+}
+
+
/* {{{ proto array array_intersect(array arr1, array arr2 [, array ...])
Returns the entries of arr1 that have values which are present in all the other
arguments */
PHP_FUNCTION(array_intersect)
@@ -3151,12 +3182,16 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type
is %d. This should never happen. Please report as a bug", data_compare_type);
return;
}
- } else if (behavior == DIFF_ASSOC) {
+ } else if ((behavior == DIFF_ASSOC) || (behavior == DIFF_KEY)) {
+ /*
+ DIFF_KEY is subset of DIFF_ASSOC. When having the former
+ no comparison of the data is done (part of DIFF_ASSOC)
+ */
diff_key_compare_func = array_key_compare;
if (data_compare_type == DIFF_COMP_DATA_INTERNAL
&&
key_compare_type == DIFF_COMP_KEY_INTERNAL) {
- /* array_diff_assoc() */
+ /* array_diff_assoc() or array_diff_key() */
if (argc < 2) {
efree(args);
@@ -3187,7 +3222,7 @@
} else if (data_compare_type == DIFF_COMP_DATA_INTERNAL
&&
key_compare_type == DIFF_COMP_KEY_USER) {
- /* array_diff_uassoc() */
+ /* array_diff_uassoc() or array_diff_ukey() */
if (argc < 3) {
efree(args);
@@ -3264,7 +3299,7 @@
*list = NULL;
if (behavior == DIFF_NORMAL) {
zend_qsort((void *) lists[i], hash->nNumOfElements,
sizeof(Bucket *), diff_data_compare_func TSRMLS_CC);
- } else if (behavior == DIFF_ASSOC) {
+ } else if (behavior == DIFF_ASSOC || behavior == DIFF_KEY) {
zend_qsort((void *) lists[i], hash->nNumOfElements,
sizeof(Bucket *), diff_key_compare_func TSRMLS_CC);
}
}
@@ -3280,7 +3315,7 @@
/* go through the lists and look for values of ptr[0] that are not in the
others */
while (*ptrs[0]) {
- if (behavior == DIFF_ASSOC
+ if ((behavior == DIFF_ASSOC || behavior == DIFF_KEY)
&&
key_compare_type == DIFF_COMP_KEY_USER) {
@@ -3292,7 +3327,7 @@
while (*ptrs[i] && (0 < (c =
diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
- } else if (behavior == DIFF_ASSOC) {
+ } else if (behavior == DIFF_ASSOC || behavior == DIFF_KEY) {
while (*ptrs[i] && (0 < (c =
diff_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
@@ -3304,19 +3339,36 @@
}
break;
} else if (behavior == DIFF_ASSOC) {
+ /*
+ In this branch is execute only when
DIFF_ASSOC. If behavior == DIFF_KEY
+ data comparison is not needed -
skipped.
+ */
if (*ptrs[i]) {
if (data_compare_type ==
DIFF_COMP_DATA_USER) {
BG(user_compare_func_name) =
args[arr_argc];
}
if (diff_data_compare_func(ptrs[0],
ptrs[i] TSRMLS_CC) != 0) {
+ /* the data is not the same */
c = -1;
if (key_compare_type ==
DIFF_COMP_KEY_USER) {
BG(user_compare_func_name) = args[argc - 1];
}
} else {
break;
+ /*
+ we have found the
element in other arrays thus we don't want it
+ in the return_value ->
delete from there
+ */
}
}
+ } else if (behavior == DIFF_KEY) {
+ /*
+ the behavior here differs from
INTERSECT_KEY in php_intersect
+ since in the "diff" case we have to
remove the entry from
+ return_value while when doing
intersection the entry must not
+ be deleted.
+ */
+ break; /* remove the key */
}
}
}
@@ -3337,7 +3389,7 @@
if (diff_data_compare_func(ptrs[0] - 1,
ptrs[0] TSRMLS_CC)) {
break;
}
- } else if (behavior == DIFF_ASSOC) {
+ } else if (behavior == DIFF_ASSOC || behavior ==
DIFF_KEY) {
/* in this case no array_key_compare is needed
*/
break;
}
@@ -3353,7 +3405,7 @@
if (diff_data_compare_func(ptrs[0]-1, ptrs[0]
TSRMLS_CC)) {
break;
}
- } else if (behavior == DIFF_ASSOC) {
+ } else if (behavior == DIFF_ASSOC || behavior ==
DIFF_KEY) {
/* in this case no array_key_compare is needed
*/
break;
}
@@ -3372,6 +3424,25 @@
efree(lists);
efree(args);
}
+
+
+/* {{{ proto array array_diff_key(array arr1, array arr2 [, array ...])
+ Returns the entries of arr1 that have keys which are not present in any of the
others arguments. This function is like array_diff() but works on the keys instead of
the values. The associativity is preserved. */
+PHP_FUNCTION(array_diff_key)
+{
+ php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_KEY,
+ DIFF_COMP_DATA_INTERNAL, DIFF_COMP_KEY_INTERNAL);
+}
+/* }}} */
+
+/* {{{ proto array array_diff_ukey(array arr1, array arr2 [, array ...], callback
key_comp_func)
+ Returns the entries of arr1 that have keys which are not present in any of the
others arguments. User supplied function is used for comparing the keys. This function
is like array_udiff() but works on the keys instead of the values. The associativity
is preserved. */
+PHP_FUNCTION(array_diff_ukey)
+{
+ php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_KEY,
+ DIFF_COMP_DATA_INTERNAL, DIFF_COMP_KEY_USER);
+}
+/* }}} */
/* {{{ proto array array_diff(array arr1, array arr2 [, array ...])
http://cvs.php.net/diff.php/php-src/ext/standard/php_array.h?r1=1.46&r2=1.47&ty=u
Index: php-src/ext/standard/php_array.h
diff -u php-src/ext/standard/php_array.h:1.46 php-src/ext/standard/php_array.h:1.47
--- php-src/ext/standard/php_array.h:1.46 Thu Jan 8 12:32:51 2004
+++ php-src/ext/standard/php_array.h Wed Jul 21 17:17:56 2004
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_array.h,v 1.46 2004/01/08 17:32:51 sniper Exp $ */
+/* $Id: php_array.h,v 1.47 2004/07/21 21:17:56 andrey Exp $ */
#ifndef PHP_ARRAY_H
#define PHP_ARRAY_H
@@ -76,12 +76,16 @@
PHP_FUNCTION(array_rand);
PHP_FUNCTION(array_unique);
PHP_FUNCTION(array_intersect);
+PHP_FUNCTION(array_intersect_key);
+PHP_FUNCTION(array_intersect_ukey);
PHP_FUNCTION(array_uintersect);
PHP_FUNCTION(array_intersect_assoc);
PHP_FUNCTION(array_uintersect_assoc);
PHP_FUNCTION(array_intersect_uassoc);
PHP_FUNCTION(array_uintersect_uassoc);
PHP_FUNCTION(array_diff);
+PHP_FUNCTION(array_diff_key);
+PHP_FUNCTION(array_diff_ukey);
PHP_FUNCTION(array_udiff);
PHP_FUNCTION(array_diff_assoc);
PHP_FUNCTION(array_udiff_assoc);
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.674&r2=1.675&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.674
php-src/ext/standard/basic_functions.c:1.675
--- php-src/ext/standard/basic_functions.c:1.674 Sun Jul 18 05:55:46 2004
+++ php-src/ext/standard/basic_functions.c Wed Jul 21 17:17:56 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.674 2004/07/18 09:55:46 wez Exp $ */
+/* $Id: basic_functions.c,v 1.675 2004/07/21 21:17:56 andrey Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -779,12 +779,16 @@
PHP_FE(array_rand,
NULL)
PHP_FE(array_unique,
NULL)
PHP_FE(array_intersect,
NULL)
+ PHP_FE(array_intersect_key,
NULL)
+ PHP_FE(array_intersect_ukey,
NULL)
PHP_FE(array_uintersect,
NULL)
PHP_FE(array_intersect_assoc,
NULL)
PHP_FE(array_uintersect_assoc,
NULL)
PHP_FE(array_intersect_uassoc,
NULL)
PHP_FE(array_uintersect_uassoc,
NULL)
PHP_FE(array_diff,
NULL)
+ PHP_FE(array_diff_key,
NULL)
+ PHP_FE(array_diff_ukey,
NULL)
PHP_FE(array_udiff,
NULL)
PHP_FE(array_diff_assoc,
NULL)
PHP_FE(array_udiff_assoc,
NULL)
@@ -794,8 +798,8 @@
PHP_FE(array_filter,
NULL)
PHP_FE(array_map,
NULL)
PHP_FE(array_chunk,
NULL)
- PHP_FE(array_combine,
NULL)
- PHP_FE(array_key_exists,
NULL)
+ PHP_FE(array_combine,
NULL)
+ PHP_FE(array_key_exists,
NULL)
/* aliases from array.c */
PHP_FALIAS(pos, current,
first_arg_force_ref)
http://cvs.php.net/co.php/php-src/ext/standard/tests/array/array_intersect_key.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/array/array_intersect_key.phpt
+++ php-src/ext/standard/tests/array/array_intersect_key.phpt
--TEST--
Test of the array_intersect_key() and array_intersect_ukey()
--FILE--
<?php
$a = array(1, 6, 2, -20, 15, 1200, -2500);
$b = array(0, 7, 2, -20, 11, 1100, -2500);
$c = array(0, 6, 2, -20, 19, 1000, -2500);
$d = array(3, 8,-2, -20, 14, 900, -2600);
$a_f = array_flip($a);
$b_f = array_flip($b);
$c_f = array_flip($c);
$d_f = array_flip($d);
/* give nicer values */
foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;}
foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;}
foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;}
foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;}
var_dump(array_intersect_key($a_f, $b_f));// keys -> 2, -20, -2500
var_dump(array_intersect_ukey($a_f, $b_f, "comp_func"));// 2, 20, -2500
var_dump(array_intersect_key($a_f, $c_f));// keys -> 6, 2, -20, -2500
var_dump(array_intersect_ukey($a_f, $c_f, "comp_func"));// 6, 2, -20, -2500
var_dump(array_intersect_key($a_f, $d_f));// -20
var_dump(array_intersect_ukey($a_f, $d_f, "comp_func"));// -20
var_dump(array_intersect_key($a_f, $b_f, $c_f));// 2, -20, -2500
var_dump(array_intersect_ukey($a_f, $b_f, $c_f, "comp_func"));// 2, -20, -2500
var_dump(array_intersect_key($a_f, $b_f, $d_f));// -20
var_dump(array_intersect_ukey($a_f, $b_f, $d_f, "comp_func"));// -20
var_dump(array_intersect_key($a_f, $b_f, $c_f, $d_f));// -20
var_dump(array_intersect_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//-20
var_dump(array_intersect_key($b_f, $c_f));// 0, 2, -20, -2500
var_dump(array_intersect_ukey($b_f, $c_f, "comp_func"));//0, 2, -20, 2500
var_dump(array_intersect_key($b_f, $d_f));// -20
var_dump(array_intersect_ukey($b_f, $d_f, "comp_func"));// -20
var_dump(array_intersect_key($b_f, $c_f, $d_f));// -20
var_dump(array_intersect_ukey($b_f, $c_f, $d_f, "comp_func"));// -20
echo "----- Now testing array_intersect() ------- \n";
var_dump(array_intersect($a, $b_f));
var_dump(array_uintersect($a, $b, "comp_func"));
var_dump(array_intersect($a, $b, $c));
var_dump(array_uintersect($a, $b, $c, "comp_func"));
var_dump(array_intersect($a, $b, $c, $d));
var_dump(array_uintersect($a, $b, $c, $d, "comp_func"));
///////////////////////////////////////////////////////////////////////
function comp_func($a, $b) {
if ($a === $b) return 0;
return ($a > $b)? 1:-1;
}
?>
--EXPECTF--
array(3) {
[2]=>
&int(4)
[-20]=>
&int(-40)
[-2500]=>
&int(-5000)
}
array(3) {
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(4) {
[6]=>
int(12)
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(4) {
[6]=>
int(12)
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(3) {
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(3) {
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(4) {
[0]=>
&int(0)
[2]=>
&int(4)
[-20]=>
&int(-40)
[-2500]=>
&int(-5000)
}
array(4) {
[0]=>
int(0)
[2]=>
int(4)
[-20]=>
int(-40)
[-2500]=>
&int(-5000)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
array(1) {
[-20]=>
int(-40)
}
----- Now testing array_intersect() -------
array(0) {
}
array(3) {
[2]=>
int(2)
[3]=>
int(-20)
[6]=>
int(-2500)
}
array(3) {
[2]=>
int(2)
[3]=>
int(-20)
[6]=>
int(-2500)
}
array(3) {
[2]=>
int(2)
[3]=>
int(-20)
[6]=>
int(-2500)
}
array(1) {
[3]=>
int(-20)
}
array(1) {
[3]=>
int(-20)
}
http://cvs.php.net/co.php/php-src/ext/standard/tests/array/array_diff_key.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/array/array_diff_key.phpt
+++ php-src/ext/standard/tests/array/array_diff_key.phpt
--TEST--
Test of the array_diff_key() and array_diff_ukey()
--FILE--
<?php
$a = array(1, 6, 2, -20, 15, 1200, -2500);
$b = array(0, 7, 2, -20, 11, 1100, -2500);
$c = array(0, 6, 2, -20, 19, 1000, -2500);
$d = array(3, 8,-2, -20, 14, 900, -2600);
$a_f = array_flip($a);
$b_f = array_flip($b);
$c_f = array_flip($c);
$d_f = array_flip($d);
$i = 1;
/* give nicer values */
foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;}
foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;}
foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;}
foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;}
echo "------ Test $i --------\n";$i++;// 1
var_dump(array_diff_key($a_f, $b_f));// keys -> 1, 6, 15, 1200
var_dump(array_diff_ukey($a_f, $b_f, "comp_func"));// 1, 6, 15, 1200
echo "------ Test $i --------\n";$i++;// 2
var_dump(array_diff_key($a_f, $c_f));// keys -> 1, 15, 1200
var_dump(array_diff_ukey($a_f, $c_f, "comp_func"));// 1, 15, 1200
echo "------ Test $i --------\n";$i++;// 3
var_dump(array_diff_key($a_f, $d_f));// 1, 6, 2, 15, 1200, -2500
var_dump(array_diff_ukey($a_f, $d_f, "comp_func"));// 1, 6, 2, 15, 1200, -2500
echo "------ Test $i --------\n";$i++;// 4
var_dump(array_diff_key($a_f, $b_f, $c_f));// 1, 15, 1200
var_dump(array_diff_ukey($a_f, $b_f, $c_f, "comp_func"));// 1, 15, 1200
echo "------ Test $i --------\n";$i++;// 5
var_dump(array_diff_key($a_f, $b_f, $d_f));// 1, 6, 15, 1200
var_dump(array_diff_ukey($a_f, $b_f, $d_f, "comp_func"));// 1, 6, 15, 1200
echo "------ Test $i --------\n";$i++;// 6
var_dump(array_diff_key($a_f, $b_f, $c_f, $d_f));// 1, 15, 1200
var_dump(array_diff_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//1, 15, 1200
echo "------ Test $i --------\n";$i++;// 7
var_dump(array_diff_key($b_f, $c_f));// 7, 11, 1100
var_dump(array_diff_ukey($b_f, $c_f, "comp_func"));//7, 11, 1100
echo "------ Test $i --------\n";$i++;// 8
var_dump(array_diff_key($b_f, $d_f));//0, 7, 2, 11, 1100, -2500
var_dump(array_diff_ukey($b_f, $d_f, "comp_func"));//0, 7, 2, 11, 1100, -2500
echo "------ Test $i --------\n";$i++;// 9
var_dump(array_diff_key($b_f, $c_f, $d_f));// 7, 11, 1100
var_dump(array_diff_ukey($b_f, $c_f, $d_f, "comp_func"));// 7, 11, 1000
function comp_func($a, $b) {
if ($a === $b) return 0;
return ($a > $b)? 1:-1;
}
?>
--EXPECTF--
------ Test 1 --------
array(4) {
[1]=>
&int(2)
[6]=>
&int(12)
[15]=>
&int(30)
[1200]=>
&int(2400)
}
array(4) {
[1]=>
int(2)
[6]=>
int(12)
[15]=>
int(30)
[1200]=>
int(2400)
}
------ Test 2 --------
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
------ Test 3 --------
array(6) {
[1]=>
int(2)
[6]=>
int(12)
[2]=>
int(4)
[15]=>
int(30)
[1200]=>
int(2400)
[-2500]=>
&int(-5000)
}
array(6) {
[1]=>
int(2)
[6]=>
int(12)
[2]=>
int(4)
[15]=>
int(30)
[1200]=>
int(2400)
[-2500]=>
&int(-5000)
}
------ Test 4 --------
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
------ Test 5 --------
array(4) {
[1]=>
int(2)
[6]=>
int(12)
[15]=>
int(30)
[1200]=>
int(2400)
}
array(4) {
[1]=>
int(2)
[6]=>
int(12)
[15]=>
int(30)
[1200]=>
int(2400)
}
------ Test 6 --------
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
array(3) {
[1]=>
int(2)
[15]=>
int(30)
[1200]=>
int(2400)
}
------ Test 7 --------
array(3) {
[7]=>
&int(14)
[11]=>
&int(22)
[1100]=>
&int(2200)
}
array(3) {
[7]=>
int(14)
[11]=>
int(22)
[1100]=>
int(2200)
}
------ Test 8 --------
array(6) {
[0]=>
int(0)
[7]=>
int(14)
[2]=>
int(4)
[11]=>
int(22)
[1100]=>
int(2200)
[-2500]=>
&int(-5000)
}
array(6) {
[0]=>
int(0)
[7]=>
int(14)
[2]=>
int(4)
[11]=>
int(22)
[1100]=>
int(2200)
[-2500]=>
&int(-5000)
}
------ Test 9 --------
array(3) {
[7]=>
int(14)
[11]=>
int(22)
[1100]=>
int(2200)
}
array(3) {
[7]=>
int(14)
[11]=>
int(22)
[1100]=>
int(2200)
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php