Hi I am trying to use the list() function to retrieve two variables from within a function. The function returns the to variables within an array.
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);
The
returnstatement is inside the switch but after thebreak, so it doesn’t run. Your function doesn’t return anything and thelistfails.Move the
returnstatement out of the switch and it should be fine.