PHP - 从循环中制动麻烦

时间:2014-11-25 00:04:45

标签: php loops

问题第一:我是否以错误的方式解决这个问题?

如果在里面有一个有条件的话,我的每次制动都很困难。我写这个只是为了节省CPU时间,但我不能从我的foreach刹车。

我正在努力遵守Active Directory严格的密码执行,我不相信拥有最大长度的密码。我发现有些网站有最大长度要求。

foreach(count_chars($new_password, 1) as $key => $value){//Strength Test Results can be derived from $value
if(!ctype_upper(chr($key))){$check_upper=1;}//if Upper-case
if(!ctype_lower(chr($key))){$check_lower=1;}//if Lower-case
if(!ctype_digit(chr($key))){$check_digit=1;}//if Numeric
if(!ctype_punct(chr($key))){$check_punct=1;}//if Symbol
if($check_upper + $check_lower + $check_digit + $check_punct>= 3){
    break; 
    }//Save us from checking the entire string 
}

2 个答案:

答案 0 :(得分:1)

您使用了错误的关键字!它应该是break

foreach(count_chars($new_password, 1) as $key => $value){//Strength Test Results can be derived from $value
if(!ctype_upper(chr($key))){$check_upper=1;}//if Upper-case
if(!ctype_lower(chr($key))){$check_lower=1;}//if Lower-case
if(!ctype_digit(chr($key))){$check_digit=1;}//if Numeric
if(!ctype_punct(chr($key))){$check_punct=1;}//if Symbol
if($check_upper + $check_lower + $check_digit + $check_punct>= 3){
    break; 
    }//Save us from checking the entire string 
}

答案 1 :(得分:1)

这很简单:break

刹车就像汽车一样。

http://php.net/manual/en/control-structures.break.php