PHP code example of gpacalcteam / cgpa-calculator

1. Go to this page and download the library: Download gpacalcteam/cgpa-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gpacalcteam / cgpa-calculator example snippets


use GpaCalc\GpaCalculator;

// Calculate semester GPA
$courses = [
    ['grade' => 'A', 'credits' => 3],
    ['grade' => 'B+', 'credits' => 4],
    ['grade' => 'A-', 'credits' => 3],
];
$gpa = GpaCalculator::calculateGpa($courses); // 3.59

// Calculate cumulative GPA
$semesters = [
    ['gpa' => 3.5, 'credits' => 15],
    ['gpa' => 3.8, 'credits' => 16],
];
$cgpa = GpaCalculator::calculateCgpa($semesters); // 3.66

// Convert percentage to GPA
$gpa = GpaCalculator::percentageToGpa(88); // 3.3

// Convert GPA to letter grade
$letter = GpaCalculator::gpaToLetter(3.5); // "A-"