--- ../../../php4-200209030900/ext/standard/array.c Sat Aug 24 04:35:58 2002 +++ array.c Wed Sep 4 00:38:16 2002 @@ -2588,9 +2588,7 @@ } /* }}} */ -/* {{{ proto array array_diff(array arr1, array arr2 [, array ...]) - Returns the entries of arr1 that have values which are not present in any of the others arguments */ -PHP_FUNCTION(array_diff) +static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior TSRMLS_DC ) { zval ***args = NULL; HashTable *hash; @@ -2614,20 +2612,23 @@ set_compare_func(SORT_STRING TSRMLS_CC); for (i=0; inNumOfElements + 1) * sizeof(Bucket *), hash->persistent); if (!list) - RETURN_FALSE; + RETURN_FALSE; lists[i] = list; ptrs[i] = list; for (p = hash->pListHead; p; p = p->pListNext) - *list++ = p; + *list++ = p; *list = NULL; - zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); + if (behavior == 1) + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_key_compare TSRMLS_CC); + else + zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); } /* copy the argument array */ @@ -2635,16 +2636,29 @@ zval_copy_ctor(return_value); /* go through the lists and look for values of ptr[0] - that are not in the others */ + that are not in the others */ while (*ptrs[0]) { c = 1; for (i=1; ih); if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) - break; + if (behavior == 0){ + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) + break; + }else{ + if (array_key_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) /* always ==1 */ + break; + } } } else { /* ptrs[0] in none of the other arguments */ @@ -2667,22 +2686,45 @@ for (;;) { if (!*++ptrs[0]) goto out; - if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) - break; + if (behavior == 0){ + if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) + break; + }else{ + if (array_key_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) /* always ==1 */ + break; + } } } } out: for (i=0; ipersistent); } efree(ptrs); efree(lists); efree(args); } + + +/* {{{ proto array array_diff(array arr1, array arr2 [, array ...]) + Returns the entries of arr1 that have values which are not present in any of the others arguments */ +PHP_FUNCTION(array_diff) +{ + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0 TSRMLS_CC); +} /* }}} */ + +/* {{{ proto array array_diff_assoc(array arr1, array arr2 [, array ...]) + Returns the entries of arr1 that have values which are not present in any of the others arguments */ +PHP_FUNCTION(array_diff_assoc) +{ + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1 TSRMLS_CC); +} +/* }}} */ + + #define MULTISORT_ORDER 0 #define MULTISORT_TYPE 1 #define MULTISORT_LAST 2 @@ -3420,3 +3462,4 @@ * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ +