Can you help me writing a PHP program to track invoices?
user
<?php

// Define an array to store the invoices
$invoices = [];

// Function to add an invoice
function addInvoice($number, $amount, $due_date) {
    global $invoices;
    $invoices[] = [
        'number' => $number,
        'amount' => $amount,
        'due_date' => $due_date
    ];
}

// Function to view all invoices
function viewInvoices() {
    global $invoices;
    echo "Number\tAmount\tDue Date\n";
    foreach ($invoices as $invoice) {
        echo $invoice['number'] . "\t" . $invoice['amount'] . "\t" . $invoice['due_date'] . "\n";
    }
}

// Add some sample invoices
addInvoice('INV001', 1000, '2022-12-31');
addInvoice('INV002', 2000, '2023-01-15');
addInvoice('INV003', 3000, '2023-02-01');

// View the invoices
viewInvoices();

?>
assistant
Could you add a way for the system to report when a invoice is overdue.
user
Sure, you can add a function to check if the due date of an invoice has passed and display a message if it has. Here is an example of how to do this:

function checkOverdue() {
    global $invoices;
    foreach ($invoices as $invoice) {
        $due_date = new DateTime($invoice['due_date']);
        if ($due_date < new DateTime()) {
            echo "Invoice {$invoice['number']} is overdue!\n";
        }
    }
}

You can call this function periodically to check for overdue invoices.
assistant