]> granicus.if.org Git - php/commitdiff
@- Fixed array_rand() to shuffle results when the number of requested
authorAndrei Zmievski <andrei@php.net>
Fri, 27 Oct 2000 14:08:33 +0000 (14:08 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 27 Oct 2000 14:08:33 +0000 (14:08 +0000)
@  elements is the same as the number of elements in the array. (Andrei)

ext/standard/array.c

index 80a22395727467656863c1a2175bdfbf1bc3aa9b..1478da640bb5d915cd4035feb1a875e6660ee79c 100644 (file)
@@ -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;
+               }
        }
 }
 /* }}} */