PHP下对字符串的递增运算代码
php  /  管理员 发布于 7年前   149
为啥? 其实很简单, PHP的手册中也有说明, 只不过恐怕很多人不会一章一节的把手册仔细阅读一遍: 也就是说, 如果: 122 在 123 在 原梓番博客 在 博主 在 1111 在
复制代码 代码如下:
for($i = 'A'; $i <= 'Z'; $i++) {
echo $i;
}
//输出是啥?
输出是:
复制代码 代码如下:
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARAS…….
PHP follows Perl's convention when dealing with arithmetic operations on character variables and not C's. For example, in Perl ‘Z'+1 turns into ‘AA', while in C ‘Z'+1 turns into ‘[‘ ( ord(‘Z') == 90, ord(‘[‘) == 91 ). Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.
在处理字符变量的算数运算时,PHP 沿袭了 Perl 的习惯,而非 C 的。例如,在 Perl 中 ‘Z'+1 将得到 ‘AA',而在 C 中,'Z'+1 将得到 ‘[‘(ord(‘Z') == 90,ord(‘[‘) == 91)。注意字符变量只能递增,不能递减,并且只支持纯字母(a-z 和 A-Z)。
上一条:
PHP生成excel时单元格内换行问题的解决方法
下一条:
深入理解PHP原理之异常机制
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号