Re: Filling an array with random input doesn't quite work [message #185229 is a reply to message #185225] |
Thu, 13 March 2014 04:31 |
Norman Peelman
Messages: 126 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 03/12/2014 11:02 PM, Norman Peelman wrote:
> On 03/12/2014 01:18 PM, richard wrote:
>> $x=1;
>> while ($x<40){
>> $yr=range(60,69);
>> shuffle($yr);
>> $ayr[$x]=$yr[$x];
>> echo $ayr[$x]."<br>";
>> $x++;
>> }
>>
>>
>> I am attempting to load an array based upon the range of numbers 60
>> through
>> 69.
>> The array will have 40 items.
>> This code produces 9 items just fine.
>> The rest of the array is empty.
>> What am I missing?
>>
>
> for ($items=1; $items<=40; $items++)
> {
> $ayr[$items] = range(60,69);
> shuffle(&$ayr[$items]);
> }
>
>
$yr = range(60,69);
for ($items=1; $items<=40; $items++)
{
$ayr[$items] = $yr;
shuffle(&$ayr[$items]);
}
or
$yr = range(60,69);
for ($items=1; $items<=40; $items++)
{
shuffle(&$yr);
$ayr[$items] = $yr;
}
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
|
|
|