In the Framework I develop (PHP language), I use multidimensional array to generate HTML reports.
There is a particular report that I can not sort properly in the SQL query, having only all the data I want to sort after array formation.
Array example:
$dados[] = array(
$cont++,"<nobr>".$nome."</nobr>",
"<div align=\"center\">".$this->tipoCliente($r['taxa'])."</div>",
$this->converte_mes($this->mesSel),
"<div align=\"right\">".number_format($r['taxa'], 2, ',', '.')."</div>",
"<div align=\"right\">".number_format($taxa, 2, ',', '.')."</div>",
"<div align=\"right\">".number_format($dife, 2, ",", ".")."</div>",
$chk
);
I even managed to reorder the array using the following function:
foreach ($dados as $key => $row)
{
$tipo[$key] = $row[2];
$val[$key] = $this->dinheiroInteiro($row[3]);
}
array_multisort($tipo, SORT_ASC, $val, SORT_DESC, $dados);
But I still have some issues with the values, and I would need to restart the counter so that it starts from 1 after reordering the array.
Just to explain better then, after using array_multisort, I reorder the array by customer type (A, B, C, D) ... and that the tie-breaking criterion is the 4 column (rate). However, after reordering through the multisort the sequence gets lost (because the initial ordering of the data played through the while is undone), since it was done by name.
Any suggestions?