php的演变脚本

时间:2014-04-28 18:39:02

标签: php mysql

我一直在尝试在PHP中改进这个脚本,因此它可以为我提供a9999999999.....9999999999(最多72个字符)的值,以便在MySQL中插入。到目前为止它停在999。我增加了Apache的内存和脚本的缩短时间,但它仍然保持不变。这是我的剧本:

 <?php
function evol($length = 1, $deb_chaine = '') {
    $tab=array("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","0","1","2","3","4","5","6","7","8","9");
    $str = '';
    if(strlen($deb_chaine) <= ($length - 1)) { 
    foreach($tab as $lettre) { 
        $str .= ' '. $deb_chaine . $lettre;
    }
    if($deb_chaine == '') { 
        $str .= evol($length, 'a');
    }
    else { // sinon
        $last = substr($deb_chaine, -1);
        $reste = substr($deb_chaine, 0, -1);
        if($last == "9") { 
        $i = strlen($deb_chaine) - 1;
        $reste = "";
        while($i >= 0) {
            if($deb_chaine[$i] == "9") {
            $reste = 'a'. $reste;
            }
            else { 
            $reste = $tab[(array_search($deb_chaine[$i], $tab) + 1)] . substr($reste, 0, -1);
            break 1;
            }
            $i--;
        }
        $new = 'a'; 
        }
        else { 
        $new = $tab[(array_search($last, $tab) + 1)];
        }
        $str .= evol($length, ($reste . $new)); 
    }
    }
    return $str;
}
echo evol(72);
?>

此代码将a的值设置为999

0 个答案:

没有答案