Change sequence values of a multidimensional array

0

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?

    
asked by anonymous 25.06.2014 / 20:33

1 answer

1

I still do not know if I understand, but it seems that you want to keep the order by the "name" as it was generated in the while loop. If so, you could include this reference array more in array_multisort:

foreach ($dados as $key => $row) 
{
    $ref[$key]  = $row[1]; // ou qualquer outro elemento de referência...
    $tipo[$key] = $row[2];
    $val[$key]  = $this->dinheiroInteiro($row[3]);
}

array_multisort($ref, ...SUA_OPÇÃO..., $tipo, SORT_ASC, $val, SORT_DESC, $dados);

So you would have the array sorted by name, having the second and third options as a "tie breaker".

    
01.08.2014 / 19:36