0
$runrwos = array();
for ($i = 0; $runrwos= mysql_fetch_assoc($run); $i++) 
{
 $DD_E_SC[$i]=$runrwos['DD_E_SC'];
 $DD_E_pKW[$i]=$runrwos['DD_E_pKW'];
 $DD_G_SC[$i]=$runrwos['DD_G_SC'];
 $DD_G_pKW[$i]=$runrwos['DD_G_pKW'];

 $data[$i] = array('DD_E_SC'=>$runrwos['DD_E_SC'],'DD_E_pKW'=>$runrwos['DD_E_pKW'], 'DD_G_SC'=>$runrwos['DD_G_SC'], 'DD_G_pKW'=>$runrwos['DD_G_pKW']);

foreach ($data as $entry) 
{
$Ep =($entry['DD_E_SC']*365+$entry['DD_E_pKW']*$SE_cons )/100;
$Gp =($entry['DD_G_SC']*365+$entry['DD_G_pKW']*$SG_cons )/100;
$Tp=$Ep+$Gp;

}
}

I have the above code that get row data from a database, once data are retrieved and stored into an array give the expected result. This code work fine, but output result as retrieved from database. My problem is when I sort the data by $Tp or $Ep or $Gp. I need to sort by descendant or ascendant value. Any help Thanks

ciccio
  • 19
  • 6
  • array_multisort($sort, SORT_DESC, $arr); –  Sep 17 '17 at 13:06
  • array_multisort($Tp, SORT_DESC, $data); I tried before but gives the following error: array_multisort(): Argument #1 is expected to be an array or a sort flag – ciccio Sep 17 '17 at 13:11
  • It should be array by this answer: https://stackoverflow.com/questions/15476085/how-to-sort-array-in-descending-order-based-on-a-specific-value –  Sep 17 '17 at 13:17
  • Once I modify the data using the formula/calculation it gives result as double, and it's not an array any more. var_dump( $Tp); float() – ciccio Sep 17 '17 at 13:23
  • it would be **a lot easier** to have the DB sort it for you in the SQL query. – Calimero Sep 17 '17 at 15:41
  • Each query involve different variables some of them from database others from user input. – ciccio Sep 17 '17 at 18:02

0 Answers0