使用 php 在大小写循环中增加字母
我正在开发一个项目,我需要循环显示这样的字母:a,A,b,B ... z,Z,aa,Aa,aA,AA,bb ... zz,ZZ ... PHP。
是否有可能以可扩展的方式做到这一点?
I am working on a project where I need to cycle through letters something like this: a,A,b,B...z,Z,aa,Aa,aA,AA,bb...zz,ZZ... in PHP.
Is it possible to do this in a scalable way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定这就是您要找的吗?
Not sure it this what you looking for ?
计算排列是一项相当繁重的任务。这将专门针对计算包含所有小写和大写字母的集合的两个字符排列的情况(我还没有测试该函数,但您应该能够弄清楚它在做什么并修复任何错误,它会至少让你开始)。
Calculating permutations is a pretty heavy task. This will do it specifically for your case of calculating two character permutations of the set containing all lower and upper case letters (I haven't tested the function but you should be able to work out what it's doing an fix any errors, it'll get you started at least).
$lowercase
和$uppercase
是分别保存 az 和 AZ 的 ASCII 值的数组。根据需要进行修改。
输出如下所示:
$lowercase
and$uppercase
are arrays that hold the ASCII values for a-z and A-Z, respectively.Modify as necessary.
This is what the output looks like:
此代码写入一行包含 1 个字符宽的元素,然后写入一行包含 2 个字符宽的元素,等等。
对于每个宽度,它通过迭代字母并从 0 到 2 ^ 宽度计数并基于二进制位进行大写来打印所有排列。
代码:
输出:
a,A,b,B,c,C,d,D,e,E,f,F,g,G,h,H,i,I,j,J,k,K,l ,L,m,M,n,N,o,O,p,P,q,Q,r,R,s,S,t,T,u,U,v,V,w,W,x,X ,y,Y,z,Z,
aa,Aa,aA,AA,bb,Bb,bB,BB,cc,Cc,cC,CC,dd,Dd,dd,DD,ee,Ee,eE,EE,ff,Ff,ff,FF,gg, Gg,gG,GG,hh,Hh,hH,HH,ii,Ii,iI,II,jj,Jj,jJ,JJ,kk,Kk,kk,KK,ll,Ll,lL,LL,m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ZZ,
This code writes one line with elements 1 char wide, then one with 2 chars wide, etc.
For each width, it prints all the permutations by iterating the letters and counting from 0 to 2 ^ width and capitalizing based on binary bits.
The code:
output:
a,A,b,B,c,C,d,D,e,E,f,F,g,G,h,H,i,I,j,J,k,K,l,L,m,M,n,N,o,O,p,P,q,Q,r,R,s,S,t,T,u,U,v,V,w,W,x,X,y,Y,z,Z,
aa,Aa,aA,AA,bb,Bb,bB,BB,cc,Cc,cC,CC,dd,Dd,dD,DD,ee,Ee,eE,EE,ff,Ff,fF,FF,gg,Gg,gG,GG,hh,Hh,hH,HH,ii,Ii,iI,II,jj,Jj,jJ,JJ,kk,Kk,kK,KK,ll,Ll,lL,LL,mm,Mm,mM,MM,nn,Nn,nN,NN,oo,Oo,oO,OO,pp,Pp,pP,PP,qq,Qq,qQ,QQ,rr,Rr,rR,RR,ss,Ss,sS,SS,tt,Tt,tT,TT,uu,Uu,uU,UU,vv,Vv,vV,VV,ww,Ww,wW,WW,xx,Xx,xX,XX,yy,Yy,yY,YY,zz,Zz,zZ,ZZ,
aaa,Aaa,aAa,AAa,aaA,AaA,aAA,AAA,bbb,Bbb,bBb,BBb,bbB,BbB,bBB,BBB,ccc,Ccc,cCc,CCc,ccC,CcC,cCC,CCC,ddd,Ddd,dDd,DDd,ddD,DdD,dDD,DDD,eee,Eee,eEe,EEe,eeE,EeE,eEE,EEE,fff,Fff,fFf,FFf,ffF,FfF,fFF,FFF,ggg,Ggg,gGg,GGg,ggG,GgG,gGG,GGG,hhh,Hhh,hHh,HHh,hhH,HhH,hHH,HHH,iii,Iii,iIi,IIi,iiI,IiI,iII,III,jjj,Jjj,jJj,JJj,jjJ,JjJ,jJJ,JJJ,kkk,Kkk,kKk,KKk,kkK,KkK,kKK,KKK,lll,Lll,lLl,LLl,llL,LlL,lLL,LLL,mmm,Mmm,mMm,MMm,mmM,MmM,mMM,MMM,nnn,Nnn,nNn,NNn,nnN,NnN,nNN,NNN,ooo,Ooo,oOo,OOo,ooO,OoO,oOO,OOO,ppp,Ppp,pPp,PPp,ppP,PpP,pPP,PPP,qqq,Qqq,qQq,QQq,qqQ,QqQ,qQQ,QQQ,rrr,Rrr,rRr,RRr,rrR,RrR,rRR,RRR,sss,Sss,sSs,SSs,ssS,SsS,sSS,SSS,ttt,Ttt,tTt,TTt,ttT,TtT,tTT,TTT,uuu,Uuu,uUu,UUu,uuU,UuU,uUU,UUU,vvv,Vvv,vVv,VVv,vvV,VvV,vVV,VVV,www,Www,wWw,WWw,wwW,WwW,wWW,WWW,xxx,Xxx,xXx,XXx,xxX,XxX,xXX,XXX,yyy,Yyy,yYy,YYy,yyY,YyY,yYY,YYY,zzz,Zzz,zZz,ZZz,zzZ,ZzZ,zZZ,ZZZ,
当然。字母字符只需使用
$a++
即可递增。为简单起见,如果只需要单倍或双倍长度,您可以......Sure. Alpha characters can be incremented with just
$a++
. For simplicity's sake if just a single or double length set is needed, you can do...