自动递增字母数字字符的PHP [英] auto increment alphanumeric characters php

查看:85
本文介绍了自动递增字母数字字符的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用php自动增加字母数字,所以它看起来像:

Is is possible to auto increment an alphanumeric number with php so it looks like:

AB001
AB002
...
...
BA001
...
...
ZZ001

然后我需要在varchar(5)中将此代码添加到mysql中.

This code will then need to be added to mysql, I was thinking a varchar(5).

干杯

推荐答案

尝试一下并查看

$x = 'AA998';
for($i = 0; $i < 10; $i++) {
    echo $x++,'<br />';
}

编辑

字母和数字相反

$x = '000AY';
for($i = 0; $i < 10; $i++) {
    echo $x++,'<br />';
}

或在ZZ999之后反转

or reversal after ZZ999

$x = 'ZZ998';
for($i = 0; $i < 10; $i++) {
    $x++;
    if (strlen($x) > 5)
        $x = '000AA';
    echo $x,'<br />';
}

这篇关于自动递增字母数字字符的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆