Jump to content

Generating Captcha Questions


kingnutter

Recommended Posts

Hi everyone,

 

I am trying to generate questions for a simple captcha system on a contact page, but I'm having trouble extracting a single entry from an associative array in the form $question, $answer.

 

This is the array:

 

$question_answers = array (
		"Is The Moon red or white?" => 'white',
		"Is rain wet or dry?" => 'wet',
		"Is The Sun blue or yellow?" => 'yellow',
		"Is fire hot or cold?" => 'hot',
		"Was Einstein clever or stupid?" => 'clever',
		"Is ice cream hot or cold?" => 'cold'
	);

 

I've tried generating a random number to extract $question_answers[$randomnumber] but the variable is always empty.

 

Should I be using a multidimensional array?

Link to comment
https://forums.phpfreaks.com/topic/195492-generating-captcha-questions/
Share on other sites

$question_answers = array (
		"Is The Moon red or white?" => 'white',
		"Is rain wet or dry?" => 'wet',
		"Is The Sun blue or yellow?" => 'yellow',
		"Is fire hot or cold?" => 'hot',
		"Was Einstein clever or stupid?" => 'clever',
		"Is ice cream hot or cold?" => 'cold'
);

$question = array_rand($question_answers);
$answer = $question_answers[$question];

 

Does that work for you?

 

Edit: Fixed

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.