<?php 

function calculate_end_date($loan_date, $no_of_terms, $holidays) {
    $date = new DateTime($loan_date);
    $terms_count = 0;

    while ($terms_count < $no_of_terms) {
        $date->modify('+1 day');
        $current = $date->format('Y-m-d');

        // Skip if holiday
        if (in_array($current, $holidays)) {
            continue;
        }

        $terms_count++;
    }

    return $date->format('Y-m-d');
}
