about shuffle()

php.internals

xuefengal

20 years ago
hi,all i have a problem. try this code on win2003,iis6,php5.1.1(isapi) ---------------------------------------- function _1_2($n) { $tmp = array(); return shuffle($tmp = range(1,$n); } echo('<pre>'.print_r(_1_2(8),True).'</pre>'); ---------------------------------------- result Array ( [0] => 6 [1] => 3 [2] => 7 [3] => 4 [4] => 8 [5] => 2 [6] => 1 [7] => 5 ) ---------------------------------------- after,try code on FreeBSD6.0r apache2.0.55,php5.1.2(cli) result is ---------------------------------------- Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 ) ---------------------------------------- manual said [bool shuffle ( array &array )] modify code ---------------------------------------- function _1_2($n) { $tmp = array(); $tmp = range(1,$n); return shuffle($tmp); } ---------------------------------------- it looks good. why on win2003,iis6 result is correct too. ---------------------------------------- OS=Win2003 IE Version=6.0.3790.1830 E:\Inetpub\php>php -v PHP 5.1.1 (cli) (built: Nov 27 2005 21:39:02) Copyright (c) 1997-2005 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2005 Zend Technologies ---------------------------------------- [/home/htdocs/]%->uname -a FreeBSD xfxy.org 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Sun Apr 9 17:54:38 UTC 2006 root@xxx:/usr/src/sys/i386/compile/devel i386 [/home/htdocs/]%->php -v PHP 5.1.2 (cli) (built: Apr 8 2006 20:29:15) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies [/home/htdocs/]%->httpd -v Server version: Apache/2.0.55 Server built: Apr 8 2006 18:41:44 [/home/htdocs/]%->         xuefengal         xuefengal@sohu.com           2006-04-28

Hannes Magnusson

20 years ago
Turn on E_STRICT. Read php.net/shuffle again. Read php.net/mailing-lists again. And at last, if you still have a problem, read http://bugs.php.net/how-to-report.php -Hannes On 4/27/06, xuefengal <xuefengal@sohu.com> wrote: