shuffle

From: Date: Fri, 11 Jan 2002 23:49:15 +0000
Subject: shuffle
Groups: php.dev 
Request: Send a blank email to php-dev+get-76721@lists.php.net to get a copy of this message
Hello, i was looking into this bug. http://bugs.php.net/bug.php?id=7045 i wrote a soultion... but i was wondering where to implement it. It could be implemented as void zend_hash_rand(HashTable *ht); or int php_rand_sort(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)); by being called from like this... zend_hash_sort(ht,php_rand_sort,NULL,1); personally i like the first soultion additionally shuffle() kill array keys.. this makes sence in some cases but not in others.. i came up with "ashuffle()" that will keep array_keys ex: $array = array(1,2,3,4,5,6); shuffle($array); you want to trash keys or because you want to be able to access $array[0] and expect it to be different on the other hand $array = array(1,2,3); foreach($array as $item) echo $item . "\n"; would print 1 2 3 $array = array(1,2,3); ashuffle($array); foreach($array as $item) echo $item . "\n"; would print say 2 3 1 but $array[0] is still 1 Follow? - Brad __________________________________________________ Do You Yahoo!? Send FREE video emails in Yahoo! Mail! http://promo.yahoo.com/videomail/

« previous php.dev (#76721) next »