Selecting a few unique, random array items by shuffling keys
MGeary helped me clean a complex function—containing many lines and loops—up into four concise lines by utilizing the shuffle function. I thought that I would posted it here in case it helps anyone else. I was trying to randomly select five unique items from a multi-dimensional array and although I had achieved the results I wanted, his suggetion allowed me to shorten my code considerably.
$howmany_want = 5;
$author_keys = array_keys($authors);
shuffle($author_keys);
$author_keys = array_slice($author_keys, 0, $howmany_want);

utahhomebook.info » Bobcats try to make it four wins in a row vs. Sixers 0:11 on Monday, 16 April 2007 Permalink | Log in to Reply
[...] Selecting a few unique, random array items by shuffling keys [...]
andrix 3:26 on Monday, 21 May 2007 Permalink | Log in to Reply
nice