php 从a循环到z,如何在PHP中从A到Z列出,然后到AA,AB,AC等

标签:php

我知道如何从A到Z列出:

foreach (range('A', 'Z') as $char) {

echo $char . "\n";

}

但是我如何从那里继续列出AA,AB,AC,AD,… AZ,BA,BB,BC等?

我做了一个快速的谷歌搜索,找不到任何东西,但我想这种方法会有所不同.

我想我可以通过使用for循环和内部字母的数组来做到这一点,尽管这种方式似乎有些粗鲁.

还有其他方法吗?

谢谢.

解决方法:

PHP具有字符串增量运算符,它完全执行以下操作:

for($x = 'A'; $x < 'ZZ'; $x++)

echo $x, ' ';

结果:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF...

参考:

PHP follows Perl’s convention when dealing with arithmetic operations on character variables and not C’s. For example, in PHP and Perl $a = ‘Z’; $a++; turns $a into ‘AA’, while in C a = ‘Z’; a++; turns a into ‘[‘ (ASCII value of ‘Z’ is 90, ASCII value of ‘[‘ is 91). Note that character variables can be incremented but not decremented and even so only plain ASCII alphabets and digits (a-z, A-Z and 0-9) are supported. Incrementing/decrementing other character variables has no effect, the original string is unchanged.

标签:php

来源: https://codeday.me/bug/20190929/1832598.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值