<?php
 namespace App\Util; use TechSoft\Laravel\Util\HtmlUtil; class QuestionExamUtil { public static function isCorrect($options, $answer) { $correctAnswer = []; foreach ($options as $index => $option) { if ($option['isAnswer']) { $correctAnswer[] = $index; } } return json_encode($answer) == json_encode($correctAnswer); } public static function isTextCorrect($correctAnswer, $answer) { return trim(HtmlUtil::text($correctAnswer)) == trim($answer); } public static function optionToAnswerLabel($answer) { $labelAnswers = []; foreach ($answer as $item) { $labelAnswers[] = chr(ord('A') + $item); } return join(', ', $labelAnswers); } }