<?php
function calculateBanglaGrade($cq_marks_array, $mcq_marks, $total_marks, $pass_marks) {
    $cq_average = 0;
    if (!empty($cq_marks_array)) {
        $cq_average = array_sum($cq_marks_array) / count($cq_marks_array);
    }

    if ($cq_average > 22 && $mcq_marks > 9) {
        $overall_marks = $cq_average + $mcq_marks;
        $percentage = ($overall_marks / $total_marks) * 100;

        if ($percentage >= 80) return 'A+';
        elseif ($percentage >= 70) return 'A';
        elseif ($percentage >= 60) return 'A-';
        elseif ($percentage >= 50) return 'B';
        elseif ($percentage >= 40) return 'C';
        elseif ($percentage >= 33) return 'D';
        else return 'F';
    } else {
        return 'F';
    }
}

$cq_marks = [60, 60];
$mcq_average = 27.5;
$grade = calculateBanglaGrade($cq_marks, $mcq_average, 100, 40);
echo 'CQ marks: ' . implode(', ', $cq_marks) . "\n";
echo 'CQ average: ' . (array_sum($cq_marks) / count($cq_marks)) . "\n";
echo 'MCQ average: ' . $mcq_average . "\n";
echo 'Overall marks: ' . ((array_sum($cq_marks) / count($cq_marks)) + $mcq_average) . "\n";
echo 'Percentage: ' . (((array_sum($cq_marks) / count($cq_marks)) + $mcq_average) / 100 * 100) . "%\n";
echo 'Grade: ' . $grade . "\n";
?>
