FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Filling an array with random input doesn't quite work
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Filling an array with random input doesn't quite work [message #185263 is a reply to message #185244] Sat, 15 March 2014 03:10 Go to previous messageGo to previous message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma:
Senior Member
On 03/14/2014 12:55 PM, Jerry Stuckle wrote:
> On 3/14/2014 11:47 AM, Norman Peelman wrote:
>> On 03/14/2014 11:00 AM, Jerry Stuckle wrote:
>>> On 3/14/2014 9:31 AM, Norman Peelman wrote:
>>>> On 03/12/2014 11:11 PM, Jerry Stuckle wrote:
>>>> > On 3/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]);
>>>> >> }
>>>> >>
>>>> >>
>>>> >
>>>> > Why would you shuffle a single item?
>>>> >
>>>> >
>>>>
>>>> $ayr[$items] is an Array
>>>>
>>>> php > print_r($ayr);
>>>> Array
>>>> (
>>>> [1] => Array
>>>> (
>>>> [0] => 60
>>>> [1] => 61
>>>> [2] => 62
>>>> [3] => 63
>>>> [4] => 64
>>>> [5] => 65
>>>> [6] => 66
>>>> [7] => 67
>>>> [8] => 68
>>>> [9] => 69
>>>> )
>>>>
>>>> )
>>>>
>>>> ... after Shuffle:
>>>>
>>>> php > shuffle(&$ayr[1]);
>>>> php > print_r($ayr[1]);
>>>> Array
>>>> (
>>>> [0] => 67
>>>> [1] => 69
>>>> [2] => 66
>>>> [3] => 61
>>>> [4] => 62
>>>> [5] => 60
>>>> [6] => 64
>>>> [7] => 68
>>>> [8] => 63
>>>> [9] => 65
>>>> )
>>>>
>>>>
>>>>
>>>
>>> Sorry, I was in a hurry and wasn't paying as much attention.
>>>
>>> But then why have 40 different arrays of 10 items each, anyway?
>>>
>>
>> I don't even know why there are 40 items when you are pulling from a
>> selection of 10 - there's going to be duplicates. Maybe that doesn't
>> matter... I think someone else actually had what Richard was really
>> after.
>>
>>
>>
>
> But each item in your list is an array. He wants single values.
>
>

Now that I checked his page I see what he was after.

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: readdir lists randomly
Next Topic: Nested PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 05:26:09 GMT 2024

Total time taken to generate the page: 0.05216 seconds