tomd79 Posted July 3, 2008 Share Posted July 3, 2008 <?php $names = $_POST['names']; if ($names == NULL ) { die("<div id='error'>No names were selected! <br /> Please select some names..</div>"); } else shuffle($names); $selected = array_rand($names, 1); echo "$selected" ?> This displays the array number not the value.. what do I do to get the value i.e. the actual name? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/113094-solved-quicky-about-array_rand/ Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 echo $names[$selected]; Quote Link to comment https://forums.phpfreaks.com/topic/113094-solved-quicky-about-array_rand/#findComment-580918 Share on other sites More sharing options...
tomd79 Posted July 3, 2008 Author Share Posted July 3, 2008 :/ thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/113094-solved-quicky-about-array_rand/#findComment-580924 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Any time. For the record and future reference, array_rand returns the key of the value in the array that it "selects". So you need to do what you want with the key. In this case, you're just putting the key into the array to get the element. Quote Link to comment https://forums.phpfreaks.com/topic/113094-solved-quicky-about-array_rand/#findComment-580930 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.