收集数组中的字符串,像这样
$resolutions = array(
'1024 x 768',
'1680 x 1050 widescreen',
'1280 x 960',
'1280 x 1024',
'1280 x 800 widescreen',
'1440 x 900 widescreen'
);
您可以使用sscanf
从字符串中提取宽度和高度。您需要将宽度和高度相乘以确定哪个分辨率具有最多的像素/是最大的分辨率。
$getPixels = function($str) {
list($width, $height) = sscanf($str, '%d x %d');
return $width * $height;
};
然后要么使用array_reduce
echo array_reduce(
$resolutions,
function($highest, $current) use ($getPixels) {
return $getPixels($highest) > $getPixels($current)
? $highest
: $current;
}
);
或者usort
数组
usort(
$resolutions,
function($highest, $current) use ($getPixels) {
return $getPixels($highest) - $getPixels($current);
}
);
echo end($resolutions);
获得最高分辨率1680 x 1050 宽屏