mirror of
https://github.com/php/php-src.git
synced 2026-04-25 17:08:14 +02:00
Add sort flags parameter to array_unique().
This commit is contained in:
@@ -2895,7 +2895,7 @@ PHP_FUNCTION(array_change_key_case)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array array_unique(array input) U
|
||||
/* {{{ proto array array_unique(array input [, int sort_flags]) U
|
||||
Removes duplicate values from array */
|
||||
PHP_FUNCTION(array_unique)
|
||||
{
|
||||
@@ -2907,11 +2907,14 @@ PHP_FUNCTION(array_unique)
|
||||
};
|
||||
struct bucketindex *arTmp, *cmpdata, *lastkept;
|
||||
unsigned int i;
|
||||
long sort_type = PHP_SORT_REGULAR;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
php_set_compare_func(sort_type TSRMLS_CC);
|
||||
|
||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
|
||||
zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array), (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
|
||||
|
||||
@@ -2930,7 +2933,6 @@ PHP_FUNCTION(array_unique)
|
||||
arTmp[i].i = i;
|
||||
}
|
||||
arTmp[i].b = NULL;
|
||||
php_set_compare_func(PHP_SORT_STRING TSRMLS_CC);
|
||||
zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), php_array_data_compare TSRMLS_CC);
|
||||
|
||||
/* go through the sorted array and delete duplicates from the copy */
|
||||
|
||||
Reference in New Issue
Block a user