Jump to content

Recommended Posts

Hello All,

 

I'm trying to work out how to use array_rand() to output a random value in an array.  So i've tested it in a single array, and it works fine:

 

$input1 = array("Link1", "Link2", "Link3", "Link4", "Link5");
$rand_keys = array_rand($input1, 2);
echo $input1[$rand_keys[0]] . "\n";

 

However, I want 'Link1', 'Link2' etc to have their own SPECIFIC URL values, so i've tried declaring another array:

 

  $input1 = array("Link1", "Link2", "Link3", "Link4", "Link5");
  $input2 = array('page.php','file.php','ends.php','smile.php'); //So 'Link1 = page.php, Link2 = file.php etc...
  $rand_keys = array_rand($input1, 2);
  echo 'The value for input 1 is: '.$input1[$rand_keys[0]] . 'and the url is '.??????????????.' "\n";

 

But can't work out how i'd grab this value - anyone kindly help?

Link to comment
https://forums.phpfreaks.com/topic/229960-array_rand-help/
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.