i have an array which is called parentArray() and is an associative array with keys as numbers (not ordered integers) and the values which may be or may not be arrays. I have a foreach() loop which loops through the parentArray() and prints the data in html table something like this:
foreach ($parentArray as $parentkey => $childArray){
echo "<tr>";
$Usage = some_function1($parentkey);
$schoolUsage = some_function2($parentkey);
echo "<td>".$Usage."</td>";
echo "<td>".$schoolUsage."</td>";
echo "</tr>";
}
I need to sort the output table in increasing order of $Usage and if 2 rows have same no of $Usage then it should compare $schoolUsage and sort them in descending order. Any ideas on how to do it because i’m completely clueless. Note that $Usage and $schoolUsage are whole numbers.
take a look at the function usort(). You can pass a custom function which does the sorting (bubble sort like).