From: terracota09 at gmail dot com
Operating system: Windows 7
PHP version: 5.3Git-2013-07-04 (Git)
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:array_rand not function
Description:
------------
http://localhost:8080/arrayAleatorio.php?juego=8
<?php
// 2 primeros numeros = nº juegos;
$a = array(9, 26, 31, 42, 4, 2, 11, 13, 19, 20, 23, 24, 28, 30, 39, 39, 1,
5,
14, 18, 36, 49, 15, 16, 25, 27, 33, 34, 38, 43, 48, 7, 10, 22, 32, 3, 6,
35, 44,
47, 8, 12, 17, 29, 37, 45, 21, 46, 40, 41);
for ($j = 1; $j < $_GET["juego"]+1; $j++) {
echo "<p style='font-family: Arial; font-size: 2em; text-align: center;
color: blue'>";
$rand_keys = array_rand($a, 6);
asort($rand_keys);
print_r($rand_keys);
//$i = 0;
for ($i = 0; $i < 6; $i++) {
//foreach ($rand_keys as $val) {
//$i++;
if ($i < 5)
echo $rand_keys[$i]." - "; //echo $val." - ";
else
echo $rand_keys[$i]; //echo $val;
}
echo "</p>";
if (($j%2) == 0)
echo "<br/>";
}
Test script:
---------------
Array ( [0] => 4 [1] => 8 [2] => 13 [3] => 16 [4] => 17 [5] => 46 ) 4 - 8 -
13 - 16 - 17 - 46
Array ( [0] => 7 [1] => 9 [2] => 11 [3] => 16 [4] => 28 [5] => 32 ) 7 - 9 -
11 - 16 - 28 - 32
Array ( [0] => 18 [1] => 23 [2] => 29 [3] => 34 [4] => 35 [5] => 43 ) 18 -
23 - 29 - 34 - 35 - 43
Array ( [0] => 1 [1] => 6 [2] => 7 [3] => 13 [4] => 27 [5] => 44 ) 1 - 6 -
7 - 13 - 27 - 44
Array ( [0] => 7 [1] => 14 [2] => 32 [3] => 41 [4] => 42 [5] => 48 ) 7 - 14
- 32 - 41 - 42 - 48
Array ( [0] => 7 [1] => 13 [2] => 15 [3] => 22 [4] => 27 [5] => 38 ) 7 - 13
- 15 - 22 - 27 - 38
Array ( [0] => 0 [1] => 2 [2] => 3 [3] => 29 [4] => 43 [5] => 49 ) 0 - 2 -
3 - 29 - 43 - 49
Array ( [0] => 18 [1] => 23 [2] => 33 [3] => 34 [4] => 36 [5] => 39 ) 18 -
23 - 33 - 34 - 36 - 39
Expected result:
----------------
0 not exist in array
Actual result:
--------------
Array ( [0] => 4 [1] => 8 [2] => 13 [3] => 16 [4] => 17 [5] => 46 ) 4 - 8 -
13 -
16 - 17 - 46
Array ( [0] => 7 [1] => 9 [2] => 11 [3] => 16 [4] => 28 [5] => 32 ) 7 - 9 -
11 -
16 - 28 - 32
Array ( [0] => 18 [1] => 23 [2] => 29 [3] => 34 [4] => 35 [5] => 43 ) 18 -
23 -
29 - 34 - 35 - 43
Array ( [0] => 1 [1] => 6 [2] => 7 [3] => 13 [4] => 27 [5] => 44 ) 1 - 6 -
7 -
13 - 27 - 44
Array ( [0] => 7 [1] => 14 [2] => 32 [3] => 41 [4] => 42 [5] => 48 ) 7 - 14
- 32
- 41 - 42 - 48
Array ( [0] => 7 [1] => 13 [2] => 15 [3] => 22 [4] => 27 [5] => 38 ) 7 - 13
- 15
- 22 - 27 - 38
Array ( [0] => 40 [1] => 2 [2] => 3 [3] => 29 [4] => 43 [5] => 49 ) 40 - 2
- 3 -
29 - 43 - 49
Array ( [0] => 18 [1] => 23 [2] => 33 [3] => 34 [4] => 36 [5] => 39 ) 18 -
23 -
33 - 34 - 36 - 39
--
Edit bug report at https://bugs.php.net/bug.php?id=65202&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65202&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65202&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65202&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65202&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65202&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65202&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65202&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65202&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65202&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65202&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65202&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65202&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65202&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65202&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65202&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65202&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65202&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65202&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65202&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65202&r=mysqlcfg