The code in my controller action:
$model = ExamsExamResults::find()->where(['student_id'=>$student_id, 'exam_short_code'=>$test])->all();
$model = ArrayHelper::map($model, 'component_name','obt_marks', 'subject_code');
json_encode($model);
gives me following output:
{
"002": {
"Written": 15
},
"004": {
"Practical": 45
},
"005": {
"Practical": 45,
"Written": 45
}
}
I would like to add obt_marks
for each subject_code
so as to get an output similar to the following
{
"002": {
"marks": 15
},
"004": {
"marks": 45
},
"005": {
"marks": 90, //45+45
}
}
this question gives some hints but I think Yii community will be benefitted by knowing how to do in a more Yii2 fashion (but still pure php solutions are also welcome).