我对用于调查的 PHP 代码有疑问。该代码仅采用一个值“answer”,如果没有答案,则采用“otherAnswer”。我需要它同时接受“答案”和“其他答案”
这是代码。感谢帮助。
protected function convertRequestToUserAnswersArray()
{
$answers = [];
if ($this->request->hasArgument('answers')) {
/** @noinspection PhpUnhandledExceptionInspection */
$requestAnswers = $this->request->getArgument('answers');
/** @noinspection PhpWrongForeachArgumentTypeInspection */
foreach ($requestAnswers as $questionUid => $requestAnswer) {
$answers[$questionUid] = $requestAnswer['answer'] ?: $requestAnswer['otherAnswer'];
}
}
return $answers;
}
慕码人2483693
繁华开满天机
largeQ