Jump to content

[SOLVED] quicky about array_rand


tomd79

Recommended Posts

<?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

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.

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.