$b_Mp ? 1 : -1; } /** * Return the index of the $haystack element which has the closest resolution * to $needle resolution string. * @param array $haystack * @param string $needle * @param function $access_function filters input parameters by doing something * like $a = $access_function($a). Leave it NULL for no filtering. */ function get_closest_res($haystack, $needle, $access_function = NULL) { $d_min = INF; $i_min = FALSE; foreach($haystack as $i => $elem) { if ($access_function !== NULL) $elem = $access_function($elem); $d = abs(res_to_width($elem) * res_to_height($elem) - res_to_width($needle) * res_to_height($needle)); if ($d < $d_min) { $d_min = $d; $i_min = $i; } } return $i_min; } /* End of file video_helper.php */ /* Location: ./application/helpers/video_helper.php */