Hello, I have no idea how to pick a random key from an array with it's value I want to create a very simple security system to prevent spam by asking users simple questions such as "Fire is Hot or Cold" might Be hard but hey life is not fair Anyway i am really stuck at how to do this I've used array_rand and managed to get a random question out of my array : <?php $questions_array = array('Fire is hot or cold' => 'hot', 'The moon is red or white' => 'white',....ETC); $rand_question = array_rand($questions_array); ?> Code (markup): But I am unable to get the answer along with the random question, Any Suggestions ? Thanks in advance, Kind Regards, Issa Shamoun
maby try this; $random_array_key = array_rand($your_array); $random_array_value = $your_array[$random_array_key]; Code (markup):
<?php $questions_array = array('Fire is hot or cold' => 'hot', 'The moon is red or white' => 'white'); $random_array_key = array_rand($questions_array); $random_array_value = $questions_array[$random_array_key]; echo $random_array_key. ' => ' . $random_array_value; ?> PHP: Just putting what EricBruggema put but making it output for you.