dongli8466 2018-01-21 12:32
浏览 66

php生成字符串增量,如ZA到ZB [重复]

This question already has an answer here:

I'm trying to generate strings in PHP like

"A" next "B"..."Z" next "ZA" next "ZB"..."ZZ" next "ZZA" next "ZZB"..."ZZZ" next "ZZZA"

Could someone help me with a method?

</div>
  • 写回答

2条回答 默认 最新

  • dongtigai3875 2018-01-21 12:42
    关注

    simply use increment operator -

    $a = "A";
    for($i=0;$i<100;$i++){
            echo $a++.' ';
    }
    

    just run this code to see the magic.

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改