Re: pick a card, any card...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9 April 2011 15:43, Curtis Maurand <curtis@xxxxxxxxxxx> wrote:
>
>
> Curtis Maurand wrote:
>>
>>
>>
>> seems to
> me that you have an array with integers as the keys.
>>
>>
> $desired_key = rand(0, count($array));
>
> sorry, I hadn't had
> coffee, yet. The line above should be:
>
> $desired_key = rand(0, count($array) - 1);
>
>>
>> $desired_value => $array[$desired_key];
>>
>> Cheers,
>> Curtis
>>
>> Simon J
> Welsh wrote:
>>> On 9/04/2011, at 3:39 PM, Scotty Logan
>> wrote:
>>>
>>>> On Apr 8, 2011, at 8:20 PM,
> Kirk Bailey
>> wrote:
>>>>> in otherwords, the
> entire idea of picking one of
>> N objects, whatever
>>>>> they are- strings, numbers,
>> gummybears, lined
> up in a listing, and
>>>>> return the one
>> item
> selected. This seems a common enough function there
>>>>>
>> should be a simple way to do it already in
> php. HOWEVER, I ain't
>>>>> findin' it that way, no
> sir/maam/other.
>>>>>
>> Maybe I am missing the
> obvious SIMPLE way to get the job done. So if we
>>>>>
> have a listing of foo's, we can title this $listing, and we
>> want
> 1 of
>>>>> them to be returned, we should see something
>> like:
>>>>> randmember($listing)
>>>>
>>>>
>> array_rand() - it's already
> built-in -
>>>>
>>
> http://php.net/manual/en/function.array-rand.php
>>>>
>>>> ÂScotty
>>>
>>> Just note that
> array_rand()
>> returns a random (or an array of random)
>>> key(s), not the
>> values.
>>> ---
>>> Simon Welsh
>>> Admin of
>>
> http://simon.geek.nz/
>>>
>>> Who said Microsoft
> never
>> created a bug-free program? The blue screen
>>>
> never, ever
>> crashes!
>>>
>>>
>>
> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
>>>
>>>
>>> --
>>> PHP General Mailing List
>> (http://www.php.net/)
>>> To unsubscribe, visit:
>> http://www.php.net/unsub.php
>>>
>>>
>>
>

$value = $aray[array_rand($array, 1)];

php -r "echo $_ENV[array_rand($_ENV,1)];"

returns a random environment variable.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux