Hi
could someone tell me how to sort the array by age? I had tried to explode $temarray into a multidimensional array, but it doesn't sort the output, do I make any mistake in the codes?
thanks in advance!
<?php
$fp = fopen ("./file.txt", "r");
while (!feof($fp))
{
$result = fgets($fp, 100);
}
fclose($fp);
$temarray = file("./file.txt");
$countfile = count($temarray);
if ($countfile ==0)
{
echo "no content";
}
echo "<table border=1>\n";
echo "<tr>
<th>Name</td>
<th>Address</td>
<th>Age</td>
</tr>";
$exploded = array(array(),array(),array());
for ($i=0; $i<$countfile; $i++)
{
// split up each line
$fields = explode("\t", $temarray[$i]);
// save each field val into our multi array
$exploded[0][] = $fields[0]; //name
$exploded[1][] = $fields[1]; //address
$exploded[2][] = $fields[2]; //age
array_multisort($exploded[2],SORT_NUMERIC, SORT_DESC);
echo " <tr>
<td>$fields[0]</td>
<td>$fields[1]</td>
<td>$fields[2]</td>
</tr>";
// Average of age
$total_age += $fields[2];
$AvgAge = $total_age/$countfile;
}
echo "</table>";
//prints average of each item
echo "Total reviews: $countfile.<br>\n";
echo "The average of reviewers age: $AvgAge .<br>\n";
?>