Re: 3d array sorting

From: Date: Wed, 26 Jul 2000 02:18:10 +0000
Subject: Re: 3d array sorting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-8187@lists.php.net to get a copy of this message
Hey Charles: Got it! Before running, clean up line wrapping inposed by the email. Enjoy, --Dan # How many rows and colums are there? $Rows = count($ar); $Cols = count($ar[0]); # Go through each row / column pair and stick it # into a temporary array. for ($RowCounter = 0; $RowCounter < $Rows; $RowCounter++) { for ($ColCounter = 0; $ColCounter < $Cols; $ColCounter++) { # Make the temporary array's key a compound # of the existing row / column keys. $Temp["$RowCounter:$ColCounter"] = $ar[$RowCounter][$ColCounter]["value"]; } } # Sort the temporary array. asort($Temp); # Start table tag. echo "<table border=\"1\">\n"; # Go through the sorted temporary array. while ( list($Key,$Val) = each($Temp) ) { # Break out the initial row/column keys # out of the temporary key. $Keys = split(":", $Key); # Display the information. echo "<tr><td>" . $ar[$Keys[0]][$Keys[1]]["nowrap"] . "</td>"; echo "<td>" . $ar[$Keys[0]][$Keys[1]]["href"] . "</td>"; echo "<td>" . $ar[$Keys[0]][$Keys[1]]["value"] . "</td></tr>"; } # End table tag. echo "</table>"; -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y More than just answers. Solutions. (SM) http://www.analysisandsolutions.com/ 4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#8187) next »