这样写对吗?
function code ($type,$length='4')
{
$text = array("1","2","3","4","5","6","7","8","9");
$alphabetic = array("a","b","c","d","e","f","g","h","i");
$mix = array_merge((array)$text, (array)$alphabetic);
$code = "";
switch ($type) {
case 'mix':
for ($i=1; $i<=$length; $i++) {
$code .= $mix[rand(0, count($mix)-1)];
}
break;
case 'number':
for ($i=1; $i<=$length; $i++) {
$code .= $text[rand(0, count($text)-1)];
}
break;
case 'words':
for ($i=1; $i<=$length; $i++) {
$code .= $alphabetic[rand(0, count($alphabetic)-1)];
}
break;
}
return $code;
}