public static function increment_idnumber($idnumber) {
        global $DB;
        while ($DB->record_exists('course', array('idnumber' => $idnumber))) {
            $matches = array();
            if (!preg_match('/(.*?)([0-9]+)$/', $idnumber, $matches)) {
                $newidnumber = $idnumber . '_2';
            } else {
                $newidnumber = $matches[1] . ((int) $matches[2] + 1);
            }
            $idnumber = $newidnumber;
        }
        return $idnumber;
    }
public static function increment_idnumber($idnumber) {
        global $DB;
        while ($DB->record_exists('course', array('idnumber' => $idnumber))) {
            $matches = array();
            if (!preg_match('/(.*?)([0-9]+)$/', $idnumber, $matches)) {
                $newidnumber = $idnumber . '_2';
            } else {
                $newidnumber = $matches[1] . ((int) $matches[2] + 1);
            }
            $idnumber = $newidnumber;
        }
        return $idnumber;
    }
public static function increment_idnumber ( $ idnumber ) { global $ DB ; while ( $ DB -> record_exists ( 'course' , array ( 'idnumber' => $ idnumber ) ) ) { $ matches = array ( ) ; if ( ! preg_match ( '/(.*?)([0-9]+)$/' , $ idnumber , $ matches ) ) { $ newidnumber = $ idnumber . '_2' ; } else { $ newidnumber = $ matches [ 1 ] . ( ( int ) $ matches [ 2 ] + 1 ) ; } $ idnumber = $ newidnumber ; } return $ idnumber ; }
Helper to increment an ID number.

This first checks if the ID number is in use.

@param string $idnumber ID number to increment.
@return string new ID number.
Helper to increment an ID number .