亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    php字符串增加1怎么實(shí)現(xiàn)

    php字符串增加1的實(shí)現(xiàn)方法:1、新建php示例文件;2、創(chuàng)建“function inc($s) {…}”方法;3、通過“while ($n– > 0) {$s = inc($s);}”計(jì)算除去最后一個(gè)字符的字符串,然后進(jìn)位即可。

    php字符串增加1怎么實(shí)現(xiàn)

    本教程操作環(huán)境:Windows10系統(tǒng)、PHP8.1版、DELL G3電腦

    php字符串增加1怎么實(shí)現(xiàn)?

    php 數(shù)字字符串 +1 操作 累加 加一 (不溢出)

    * inc.php

    <?php   function inc($s) {     if (empty($s)) {return "1";}     if ( ! isset($s[1]) ) {         $code = ord($s[0]) + 1;         if ($code <= ord("9")) {             return chr($code);         }         return "10";     }     $n = strlen($s);     $code = ord($s[$n-1]) +1;     if ($code <= ord("9")) {         return substr($s, 0, $n-1).chr($code);     }     return inc(substr($s, 0, $n-1))."0"; }   $s = "2147483647"; $n = 10000; while ($n-- > 0) {     // printf("%sn", $s);     $s = inc($s); } printf("%sn", $s); // "2147493647"
    登錄后復(fù)制

    遞歸,如果需要進(jìn)位, 先計(jì)算除去最后一個(gè)字符的字符串, 最后一個(gè)字符置為'0'; 單個(gè)數(shù)字字符0-9顯然好處理。

    * test:

    <?php   $m = 2147483647;   $n = 10000; while ($n-- > 0) {     // printf("%dn", $m);     $m++; } printf("%dn", $m);
    登錄后復(fù)制

    比較結(jié)果一致

    * add2.php // 遍歷1-4位大寫字母

    <?php   function add($s) {     if (empty($s)) {return "A";}     if ( ! isset($s[1]) ) {         $code = ord($s[0]) + 1;         if ($code <= ord("Z")) {             return chr($code);         }         return "AA";     }     $n = strlen($s);     $code = ord($s[$n-1]) +1;     if ($code <= ord("Z")) {         return substr($s, 0, $n-1).chr($code);     }     return add(substr($s, 0, $n-1))."A"; }   $s = ""; do {     $s = add($s);     printf("%sn", $s); } while ($s != "ZZZZ");
    登錄后復(fù)制

    推薦學(xué)習(xí):《PHP視頻教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)