Mr Chris Posted March 8, 2011 Share Posted March 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/229960-array_rand-help/ Share on other sites More sharing options...
sasa Posted March 8, 2011 Share Posted March 8, 2011 $input2[$rand_keys[0]] Quote Link to comment https://forums.phpfreaks.com/topic/229960-array_rand-help/#findComment-1184378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.