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

6
  • array_multisort($sort, SORT_DESC, $arr); Commented Sep 17, 2017 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 Commented Sep 17, 2017 at 13:11
  • It should be array by this answer: stackoverflow.com/questions/15476085/… Commented Sep 17, 2017 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() Commented Sep 17, 2017 at 13:23
  • it would be a lot easier to have the DB sort it for you in the SQL query. Commented Sep 17, 2017 at 15:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.