Jump to content

Pick a random array element


AdRock

Recommended Posts

I am trying to make myself a dummy data generator to populate my database but i'm having trouble getting a random name out of the array.

 

I am trying to create a 150 long list of random names from the array but all i get is a list of numbers which i presume are the key to each element.  What I want is to data

 

Any ideas how i can fix this?

 

$firstnames = array("0" =>"JACK",
"1" =>"OLIVER",
"2" =>"THOMAS",
"3" =>"HARRY",
"4" =>"JOSHUA");

for($i=0; $i < 150; $i++) {
$rand_firstname = array_rand($firstnames,1);
$rand_firstname = ucwords($rand_firstname);

print_r($rand_firstname);
}

Link to comment
https://forums.phpfreaks.com/topic/196495-pick-a-random-array-element/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.