What are the best practices for managing running numbers in PHP when dealing with yearly increments?

When managing running numbers in PHP with yearly increments, it is important to store the current number in a database or file to persist across different script executions. To increment the number each year, you can check the current year and reset the number to 1 if it is a new year. This ensures that the running number continues to increment yearly.

// Retrieve the current year
$currentYear = date('Y');

// Retrieve the last stored number from the database or file
$lastNumber =  // Retrieve last number from database or file

// Check if it is a new year and reset the number if necessary
if ($lastNumber['year'] != $currentYear) {
    $runningNumber = 1; // Reset the number to 1 for the new year
} else {
    $runningNumber = $lastNumber['number'] + 1; // Increment the number
}

// Save the updated running number back to the database or file
// Update database or file with the new running number for the current year