Skip to content

Instantly share code, notes, and snippets.

@resmo
Last active October 13, 2015 00:28
Show Gist options
  • Save resmo/4110603 to your computer and use it in GitHub Desktop.
Save resmo/4110603 to your computer and use it in GitHub Desktop.
next_bind_serial builder
<?php
class OutOfSerialsException extends Exception {}
function next_bind_serial($serial) {
$today = date("Ymd");
for ($i = 0; $i < 100; $i++) {
$new_serial = $today.sprintf("%02d",$i);
if ($serial < $new_serial) {
return $new_serial;
}
}
throw new OutOfSerialsException;
}
$serial = "2012111902";
echo next_bind_serial($serial);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment