Hi all! The following code is fully functional. I am having trouble with array_multisort(); It is re-ordering the first array but not the second. Here is an example of the arrays the script makes to start with:
[code=html]$order
Array
(
[0] => 20
[1] => 10
)
[code=html]$mxhosts
Array
(
[0] => smtp.lcn.biz
[1] => our-den.moralet.com
)
and here is the script:
[code=php]<?php
function win32_getmxrr($hostname, &$mxhosts, &$Weights = NULL)
{
$mxhosts = array();
exec(‘nslookup -type=mx ‘.$hostname, $result_arr);
foreach($result_arr as $line)
{
if (preg_match(“/.*mail exchanger = (.*)/”, $line, $matches))
$mxhosts[] = $matches[1];
if (preg_match(“/.*MX preference = ([0-9]*)/”, $line, $weight)){
$order[] = $weight[1];
}
}
var_dump($order); // This is just for test purposes
echo ‘<br>’;
var_dump($mxhosts);
echo ‘<br>’; // End: this is just for test purposes
if (count($order) > 0)
{
array_multisort($order, $mxhosts); // This is what I am having trouble with. It is not sorting the $mxhosts array.
if (!is_null($Weights))
{
$Weights = $order;
}
var_dump($order); // This is just for test purposes
echo ‘<br>’;
var_dump($mxhosts);
echo ‘<br>’; // End: this is just for test purposes
return True;
}
else
{
return False;
}
} // End function
//test the function
$weight = array();
echo <<<END
<br><form method=”post” action=”http://{$_SERVER[‘HTTP_HOST’]}{$_SERVER[‘PHP_SELF’]}”>
Enter domain to test:
<input type=”text” name=”domain” id=”domain” value=”moralet.com”>
<input id=”submit” type=”submit” value=”Send”>
</form>
END;
if($_POST[‘domain’]){
$getmxrr = win32_getmxrr($_POST[‘domain’], $mxhosts, $weight);
if(!empty($getmxrr)){
$i = 1;
echo ‘Number of MX records: ‘.count($mxhosts).'<br>’;
foreach($mxhosts as $key => $value){
print ‘<br>Record ‘.$i.’: ‘.$value.'<br>Preference: ‘.$weight[$key].'<br>’;
$i++;
}
}else{
echo ‘No MX record found.’;
}
} // End: test the function
?>
This is what I end up with after array_multisort(); As you will see only the first array has been sorted. I want both sorted in the same fashion.
[code=html]$order
Array
(
[0] => 10
[1] => 20
)
[code=html]$mxhosts
Array
(
[0] => smtp.lcn.biz
[1] => our-den.moralet.com
)