Hi I am trying to return two variables from a function using the following code:
$img_width = 4000;
$img_height = 3000;
function change_large_image_size($img_width, $img_height)
{
if(($width == $height) && ($width > 790) && ($height > 790)){$case = 1;}
if($width < $height && ($width > 790) && ($height > 790)){$case = 2;}
if($width > $height && ($width > 790) && ($height > 790)){$case = 3;}
switch($case)
{
case 1:
$new_width = 790;
$new_height = 790;
break;
case 2:
$new_height = 790;
$ratio = $new_height / $height;
$new_width = round($width * $ratio);
break;
case 3:
$new_width = 790;
$ratio = $new_width / $width;
$new_height = round($height * $ratio);
break;
default:
$new_width = $img_width;
$new_height = $img_height;
break;
}
return array($new_width, $new_height);
}
list($new_width, $new_height) = change_large_image_size($img_width, $img_height);
echo '<p>' . $img_width . $img_height . '<br>' . $new_width . $new_height . '</p>';
solved the initial problem I was having but have a new one
For some reason the function keeps throwing out the default case in the switch.
Obviously none of your three conditions hold, so
$caseends up evaluated asnullin theswitchstatement and the default branch is taken.