PHP流程控制语句-swith...case语句



    function make_char($length = 1){  //生成随机字符串
    $chars = 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', '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'
    );  
    $char_txt = '';  
    for($i = 0; $i < $length; $i++){  
        $char_txt .= $chars[array_rand($chars)];  
    }
    return $char_txt;
    }

    function switch_numbers($a){//switch 数字
        switch ($a) {
            case 1:
                echo "$a
"
; break; case 2: echo "$a
"
; break; case 3: echo "$a
"
; break; case 4: echo "$a
"
; break; case 5: echo "$a
"
; break; default: echo "others
"
; break; } } function switch_strings($b){//switch 字符串 switch ($b) { case 'a': echo "$b
"
; break; default: echo "$b
"
; break; } } switch_numbers(rand(1,6)); switch_strings(make_char()); ?>

你可能感兴趣的:(PHP)