I would strongly advise NOT to use global ones.
Most likely, you better return from the function:
function imageSize($name, $nr, $category){ $path = 'ad_images/'.$category.'/'.$name.'.jpg'; $path_thumb = 'ad_images/'.$category.'/thumbs/'.$name.'.jpg'; list($width, $height) = getimagesize($path); list($thumb_width, $thumb_height) = getimagesize($path_thumb); ${'thumb_image_' . $nr . '_width'} = $thumb_width; ${'thumb_image_' . $nr . '_height'} = $thumb_height; ${'image_' . $nr . '_width'} = $width; ${'image_' . $nr . '_height'} = $height; $myarr = array(); $myarr['thumb_image_' . $nr . '_width'] = $thumb_width; $myarr['thumb_image_' . $nr . '_height'] = $thumb_height; $myarr['image_image_' . $nr . '_width'] = $width; $myarr['image_image_' . $nr . '_height'] = $height; return $myarr; }
$myImage = imageSize($name, $nr, $category);
then you get access to each var:
echo $myImage['thumb_image_1_width']; echo $myImage['thumb_image_1_height']; echo $myImage['image_1_weight']; echo $myImage['image_1_height'];
and etc.
Lizard
source share