note 94093 added to function.array-rand
| From: | Yousha at YPY dot ir | Date: | Thu, 15 Oct 2009 21:57:29 +0000 |
| Subject: | note 94093 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161792@lists.php.net to get a copy of this message | ||
Faster than all Random array(Element) functions in this PAGE:
# Copyright Y.P.Y & http://forum.IranPHP.ORG
function Random_Element($Ary_Input, $Int_Count)
{
if(count(&$Ary_Input) >= $Int_Count): return($Ary_Input);
endif;
do
{
for($i = 0; $i < $Int_Count; $i ++): $_Ary_Output[]= $Ary_Input[array_rand(&$Ary_Input)];
endfor;
$_Ary_Output= array_unique($_Ary_Output);
if(count(&$_Ary_Output) == $Int_Count): break;
else: unset($_Ary_Output);
endif;
} while(count(&$_Ary_Output) < $Int_Count);
return($_Ary_Output);
}
Enjoy ;).
----
Server IP: 69.147.83.197
Probable Submitter: 79.132.197.238
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/94093
Del: integrated -- https://master.php.net/note/delete/94093/integrated
Del: useless -- https://master.php.net/note/delete/94093/useless
Del: bad code -- https://master.php.net/note/delete/94093/bad+code
Del: spam -- https://master.php.net/note/delete/94093/spam
Del: non-english -- https://master.php.net/note/delete/94093/non-english
Del: in docs -- https://master.php.net/note/delete/94093/in+docs
Del: other reasons-- https://master.php.net/note/delete/94093
Reject -- https://master.php.net/note/reject/94093
Search -- https://master.php.net/manage/user-notes.php