Here is a class that you can use to sort with multiple sizes
Note. You must have PHP5
class MultiDimensionSort
{
const ASCENDING = 0,DESCENDING = 1;
public $sortColumn,$sortType;
public function __construct($column = 'price', $type = self::ASCENDING)
{
$this->column = $column;
$this->type = $type;
}
public function cmp($a, $b)
{
switch($this->type)
{
case self::ASCENDING:
return ($a[$this->column] == $b[$this->column]) ? 0 : (($a[$this->column] < $b[$this->column]) ? -1 : 1);
case self::DESCENDING:
return ($a[$this->column] == $b[$this->column]) ? 0 :(($a[$this->column] < $b[$this->column]) ? 1 : -1);
default:
assert(0);
}
}
}
Just as you have an array called summary with the contents above the array. than you can sort by following the instructions. // Assuming your array variable$summary
$s = new MultiDimensionSort('total_sales', MultiDimensionSort::DESCENDING);
usort($summary, array($s, 'cmp'));
print"<pre>";print_r($summary);
!
, .