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 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]; 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!! 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. 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
Archived
This topic is now archived and is closed to further replies.