Jump to content

array_Rand help?


Mr Chris

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

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.