summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>2000-10-27 14:08:33 +0000
committerAndrei Zmievski <andrei@php.net>2000-10-27 14:08:33 +0000
commitd4cf62f86fd96ed21bb0069fb540747170499a35 (patch)
tree92f269fcafc4dc3e17796593b72aec17be151465
parentb52239729886d57369a550892218eff1c778456b (diff)
downloadphp-git-d4cf62f86fd96ed21bb0069fb540747170499a35.tar.gz
@- Fixed array_rand() to shuffle results when the number of requested
@ elements is the same as the number of elements in the array. (Andrei)
-rw-r--r--ext/standard/array.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 80a2239572..1478da640b 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2764,6 +2764,13 @@ PHP_FUNCTION(array_rand)
num_avail--;
zend_hash_move_forward(Z_ARRVAL_PP(input));
+ }
+
+ if (num_req_val == num_avail) {
+ if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)mergesort, array_data_shuffle, 1) == FAILURE) {
+ zval_dtor(return_value);
+ RETURN_FALSE;
+ }
}
}
/* }}} */