2012-01-19 32 views
0

您好我想使用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); 
+0

var_dump(thumb_dimensions($ case,$ image_width,$ image_height))''的結果是什麼? – afuzzyllama

回答

5

return聲明是在交換機內部,但break後,所以它不會運行。您的功能不會返回任何內容,並且list失敗。

return語句移出交換機,它應該沒問題。