无法从函数中检索多个变量

crm*_*ham 0 php return function list

您好我正在尝试使用list()函数从函数中检索两个变量.该函数返回数组中的变量.

function thumb_dimensions($case, $image_width, $image_height){
    switch($case){
        case 1:
            $thumb_width    =   100;
            $thumb_height   =   100;
        break;
        case 2:
            $thumb_height   =   100;
            $ratio          =   $thumb_height / $image_height;
            $thumb_width    =   round( $image_width * $ratio );
        break;
        case 3:
            $thumb_width    =   100;
            $ratio          =   $thumb_width / $image_width;
            $thumb_height   =   round($image_height * $ratio);
        break;


        return array($thumb_width, $thumb_height);
    }


}

$case = 3;
list($thumb_width, $thumb_height) = thumb_dimensions($case, $image_width, $image_height);
Run Code Online (Sandbox Code Playgroud)

Mar*_*niz 5

return语句在交换机内但在之后break,因此它不会运行.您的函数不会返回任何内容而list失败.

return语句移出开关,应该没问题.