Location: PHPKode > scripts > SortMultiArray > sortmultiarray/SortMultiArray_Example.php
<?
	//lets put some data together in an associative array
	$DataArray = array(	array("StudentID"=>"215-569-8212","StudentName"=>"Frank Justor","AvgGrade"=>95,"FinalGrade"=>"A"),
						array("StudentID"=>"254-965-5216","StudentName"=>"Bob Grant","AvgGrade"=>85,"FinalGrade"=>"B"),
						array("StudentID"=>"569-985-3654","StudentName"=>"Mary Filler","AvgGrade"=>92,"FinalGrade"=>"A"),
						array("StudentID"=>"636-965-8544","StudentName"=>"George Karlin","AvgGrade"=>68,"FinalGrade"=>"D"),
						array("StudentID"=>"535-964-9635","StudentName"=>"Kelly Don","AvgGrade"=>83,"FinalGrade"=>"B"),
						array("StudentID"=>"965-965-3215","StudentName"=>"Manny Orfis","AvgGrade"=>73,"FinalGrade"=>"C"),
						array("StudentID"=>"325-964-8534","StudentName"=>"Garry Jonah","AvgGrade"=>76,"FinalGrade"=>"C"),
						array("StudentID"=>"952-637-7463","StudentName"=>"Jennifer Loris","AvgGrade"=>53,"FinalGrade"=>"F"),
						array("StudentID"=>"495-657-8545","StudentName"=>"Jannie Marlow","AvgGrade"=>81,"FinalGrade"=>"B"),
						array("StudentID"=>"125-964-9876","StudentName"=>"Joe Stewert","AvgGrade"=>79,"FinalGrade"=>"C")
					  );
?>
<?
	if (empty($Col))
		$Col = "StudentID";
	if (empty($Sort))
		$Sort = 0;
?>
<html>
<head>
<title>Sort a Multi-Dimmensional Array</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Created By: Sunny Rajpal<br>
  Email: <a href="mailto:hide@address.com">hide@address.com</a></p>
<p>Click on [Asc] to sort that column in ascending order<br>
  Click on [Desc] to sort that column in descending order</p>
<table width="100%" border="1">
  <tr> 
    <td><div align="center">[<a href="SortMultiArray_Example.php?Col=StudentID&Sort=0">Asc</a>] 
        Student ID [<a href="SortMultiArray_Example.php?Col=StudentID&Sort=1">Desc</a>]</div></td>
    <td><div align="center">[<a href="SortMultiArray_Example.php?Col=StudentName&Sort=0">Asc</a>] 
        Student Name [<a href="SortMultiArray_Example.php?Col=StudentName&Sort=1">Desc</a>]</div></td>
    <td><div align="center">[<a href="SortMultiArray_Example.php?Col=AvgGrade&Sort=0">Asc</a>] 
        Average Grade [<a href="SortMultiArray_Example.php?Col=AvgGrade&Sort=1">Desc</a>]</div></td>
    <td><div align="center">[<a href="SortMultiArray_Example.php?Col=FinalGrade&Sort=0">Asc</a>] 
        Final Grade [<a href="SortMultiArray_Example.php?Col=FinalGrade&Sort=1">Desc</a>]</div></td>
  </tr>
<?
	//sort the array 
	include_once("./SortMultiArray_Class.php");
	$SMA = new SortMultiArray($DataArray,$Col,$Sort);
	$SortedArray = $SMA->GetSortedArray();
	
	foreach ($SortedArray as $Value)
	{
		echo "<tr>\n";
    	echo "<td>".$Value['StudentID']."</td>\n";
    	echo "<td>".$Value['StudentName']."</td>\n";
    	echo "<td>".$Value['AvgGrade']."</td>\n";
    	echo "<td>".$Value['FinalGrade']."</td>\n";
  		echo "</tr>\n";
	}
?>
</table>
</body>
</html>
Return current item: SortMultiArray