PLEASE HELP!!!
I have a 2 dim array (5x5) - I want to sort random integers that are contained within the array (from smallest to largest).... When I use asort() function I get the orginal table back... Also, the bubble sort didn't work... it only sorts the rows indpendently....
Reference:/// Can someone PLEASE Help and point out what is wrong.... feel free to write back a few lines of code that may work....
Thanks!
<?php
// Assign values ....
$table = array();
$x=0;
$min=60;
$max=101;
echo "<table border=\"1\">";
for($row=1;$row<=4; $row++){
echo "<tr>\n";
for($col=1;$col<=5; $col++){
$x=rand($min,$max);
$table[$row][$col] = $x;
echo"<td>$x</td>\n";
}
echo "</tr>";
}
echo "</table>";
asort($table);
//Try her to re-display the table using BUBBLE SORT each row gets sorted but not the entire table...
echo "<table border=\"1\">";
for($row=1;$row<=5; $row++){
echo "<tr>\n";
for($col=1;$col<=5; $col++){
for($j=1;$j<=5;$j++){
if ($table[$row][$col]>$table[$row][$col+1]){
$temp=$table[$row][$col];
$table[$row][$col]=$table[$row][$col+1];
$table[$row][$col+1]=$temp;
}
}
}
echo "</tr>";
}
echo "</table>";
//
asort($table); // The asort() does not affect the table - it gives back the same one....
echo "<table border=\"1\">";
for($row=1;$row<=4; $row++){
echo "<tr>\n";
for($col=1;$col<=5; $col++){
$y= $table[$row][$col];
echo"<td>$y</td>\n";
}
echo "</tr>";
}
echo "</table>";
?>
:)