내가 여기서 뭘 잘못하고 있니? 사용자 이름 문자열은 2 자 미만이지만 여전히 오류 []를 설정하지 않습니까?배열의 도움
등록 : 귀하의 기능이 errors
라는 이름의 지역 변수, 당신이 예상되었을 수없는 글로벌 errors
에 영향을 미치는 validate_username($username);
$errors = validate_username($username);
에
$errors = array();
$username = "l";
validate_username($username);
if (empty($errors)) {
echo "nothing wrong here, inserting...";
}
if (!empty($errors)) {
foreach ($errors as $cur_error)
$errors[] = '<li class="warn"><span>'.$cur_error.'</span></li>';
}
function validate_username($username) {
$errors = array();
if (strlen($username) < 2)
$errors[] = "Username too short";
else if (strlen($username) > 25)
$errors[] = "Username too long";
return $errors;
}