Answer to Question #2123 in AJAX | JavaScript | HTML | PHP for Camille

Question #2123
How to randomly select 5 elements from an String Array?
1
Expert's answer
2011-03-29T09:15:17-0400
Some example:

$array = array('first', 'second', 'third', 'forth', 'fifth', 'sixth', 'seventh', 'eighth');

for ($i = 0; $i < 5; $i++)
{
$random = rand(0, count($array)-1);
print($array[$random].' ');
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS