[thelist] PHP 2D array sort

Bigpant bigpant at btinternet.com
Tue May 21 17:02:00 CDT 2002

>I put together somthing a while back that performed this type of thing.

Thanks for that, Michael. I sure understand user defined sorting better
It wasn't quite what I was looking for, though, but I came up with the
(an) answer:

I have a static web search function that counts the number of terms
found in each url. Hence the array(array("result" => "", "qty" => 0)). I
want to display the results with the most first, so I need to sort
'qty', but keep the keys the same in 'result'.

I used this:

$a = array(array("qty" => 0, "result" => ""));
$a['result'][] = "two";
$a['qty'][] = 2;

$a['result'][] = "one";
$a['qty'][] = 1;

while (list($key, $value) = each($a['qty']))
	echo "($key) $value - " . $a['result'][$key];
	echo "<br>";

Once I figured that I simply needed to *order* the 'qty' element, and
not necessarily alter the keys, I had it sussed.


More information about the thelist mailing list