【发布时间】:2019-12-16 23:48:51
【问题描述】:
我有以下关键字。我希望最终答案(可能是 answer_1、answer_2、answer_3)是包含“问题”中的关键字的答案。
$question = 'how old are you'
$key_word_1 = array('old', 'are');
$answer_1 = 'this is my age';
$key_word_2 = array('yes', 'no');
$answer_2 = 'this is a question';
$key_word_3 = array('tall', 'short');
$answer_3 = 'this are my measures';
$key_word_4 = array('back', 'blue');
$answer_4 = 'My colorus';
echo $final_answer;
'this is my age' . #----> because 'old' and 'are' are contained in $question
【问题讨论】:
-
您需要拆分字符串,然后遍历每个索引并针对每个问题进行检查,将计数加一。但是,如果你最终得到一个均分(两个不同的问题中的一个词,总共两个词)怎么办?