Jump to content

uasort()


henryhenry

Recommended Posts

HelloI am trying to use uasort for an array like this (first code box). I am trying to have it ordered by the rank, keeping the array keys and structure the same. When I run it in my code, I get bool(true) result, rather than another array. I can't see where I'm going wrong...

$array is - [0] =>- - [item] => hello- - [rank] => 20- [1] =>- - [item] => world- - [rank] => 35- [2] =>- - [item] => help- - [rank] => 23

The compare function I'm trying is as on php.net (but I added ['rank'])

function compareRank($a, $b) {	if ($a['rank'] == $b['rank']) { 	  return 0; 	}	return ($a['rank'] < $b['rank']) ? -1 : 1;  }

My code has the following in it:

$array= uasort($array, "compareRank");

Thanks!!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...