PHP Function to Return Lowest MX Record

30 09 2010
This is a quick and simple one, but I admittedly started off with a for loop before coming across array_multisort. This turned out to be very useful for an application I'm working on.


// example
echo "Google's lowest MX is:  " . lowestmx("google.com");

function lowestmx($server) {
    getmxrr($server, &$mxhosts, &$weight);
    array_multisort($weight, $mxhosts);
    return $mxhosts[0];
}