Sort alexa rank live

161 views Asked by At

An excel file contains 2 columns and 100 rows. The first column is serial numbers and the second one is domain names. I am able to get alexa ranks of the websites using this script. I need the ranks obtained be sorted in ascending order. Also the respected urls should be sorted accordingly. What should I do?

<?php $data = wp_excel_cms_get("top100"); ?>
<?php foreach($data as $entry): ?>

<? $url = "http://". $entry[1]; 
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$web=(string)$xml->SD[0]->attributes()->HOST;
?>

<?php echo  $rank."&nbsp;";?><a href ="<?php echo "http://". $entry[1]; ?>"target="_blank"><?php echo $entry[1];?></a>
<hr />
<?php endforeach; ?>
1

There are 1 answers

0
ClickLabs On

Use two loops.

First loop queries alexa and stores results in an array rank => host. Then sort array by keys (see: http://php.net/manual/en/function.ksort.php).

Then loop over sorted array to output data.