Jump to content

[SOLVED] Arrays: Choose Random Element


eRott

Recommended Posts

Okay, I have having a bit of trouble. I have an array contain 6 strings of numbers. I want to randomly pick one of these strings of numbers and output that chosen string. My problem is, it does not output the string, it will output a single number. What am I doing wrong?

 

$folders = array("150593", "234156", "326514", "463152", "523574", "642552");
$folder = array_rand($folders, 1);

$target = "path/".$folder;

 

Take care.

Link to comment
Share on other sites

it is because array_rand returns the key not the value

 

$folders = array("150593", "234156", "326514", "463152", "523574", "642552");
$i = array_rand($folders, 1);

$target = "path/".$folders[$i];

 

Try that

 

Ray

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.