我正在尝试创建一个为表单验证目的创建随机安全问题的函数。不过我很挣扎,因为我似乎无法访问变量的最终值。php.net 以外的任何帮助将不胜感激,我去过那里,但我不是 100% 了解如何创建我的第一个对象。
class question {
public $sq = '';
public $answer = '';
function generate_question() {
$questions = array( array( question => "What color is the sky?",
answer => "blue"),
array(question => "What month is after April?",
answer => "May"),
array(question => "What animal is usually chasen by a cat?",
answer => "mouse"),
array(question => "What color is banana?",
answer => "yellow"),
array(question => "What is a next day after Monday?",
answer => "Tuesday"),
);
$question = array_rand($questions);
return $sq = $questions[$question]['question'];
return $answer = $questions[$question]['answer'];
}
}
$sqo = new question();
echo $sqo->sq . $sqo->answer;