Shadowing Posted February 12, 2012 Share Posted February 12, 2012 Hey guys i have a array i made and im wanting to grab a random value out of the array. The only way i can see to do this looking at the list of array functions is i need to random a key first? and then return the value assigned to the random key i just generated? I only see a function that lets me do the opposite. array_search() so now that i have generated a random key how do I grab just the value from the array using the random key. or is there a function i can just random value? $explode_names = explode(" ", $planet_names); $random_key_name = (array_rand($explode_names, 1)); echo $random_key_name; Quote Link to comment https://forums.phpfreaks.com/topic/256943-extracting-a-value-from-a-array-using-the-key/ Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 Well, you know the name of the array, $explode_names; and the value of the key, $random_key_name, so how do you usually reference an array element? $name[$key] Quote Link to comment https://forums.phpfreaks.com/topic/256943-extracting-a-value-from-a-array-using-the-key/#findComment-1317246 Share on other sites More sharing options...
Shadowing Posted February 12, 2012 Author Share Posted February 12, 2012 thanks Pikachu2000 finally found on tizag.com where it shows that. Quote Link to comment https://forums.phpfreaks.com/topic/256943-extracting-a-value-from-a-array-using-the-key/#findComment-1317247 Share on other sites More sharing options...
litebearer Posted February 12, 2012 Share Posted February 12, 2012 Might look at http://www.php.net/manual/en/function.shuffle.php Quote Link to comment https://forums.phpfreaks.com/topic/256943-extracting-a-value-from-a-array-using-the-key/#findComment-1317249 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.