replace: $answer->feedback = $question->feedback[$key]; with: $answer->response = $question->feedback[$key]; NOTE.- it is a pity that the naming conventions of such objects" as feedback and responses is not coherent throughout Moodle, causing such bugs.