Lt Llama Posted January 18, 2007 Share Posted January 18, 2007 I save some values in an array with:[code=php:0]$myArray[$i++] = array($value1,$value2);[/code]Lets say I have the following content of $myArray:$myArray[0]: $value1 = "1", $value2= "a"$myArray[1]: $value1 = "2", $value2= "b"$myArray[2]: $value1 = "3", $value2= "c"$myArray[3]: $value1 = "1", $value2= "d"How do I sort reverse on $value1 so I can use:[code=php:0]for ($j=0; $j <= $i; $j++) { echo $myArray[$j][0],"...",$myArray[$j][1],"<br>";}[/code]to print[tt]3 ... c2 ... b1 ... a1 ... d[/tt]I wish I could use something likesort($myArray[$value1]);Sorry, but I just don't get this.Isn't there a simple php function to sort an indexed array based on a value in the array?p.s. $value1 and $value2 contains non unique numbers. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 18, 2007 Share Posted January 18, 2007 I'm thinking your looking to do this:http://us3.php.net/manual/en/function.arsort.php Quote Link to comment Share on other sites More sharing options...
Lt Llama Posted January 19, 2007 Author Share Posted January 19, 2007 [quote author=The Little Guy link=topic=123015.msg508001#msg508001 date=1169146077]I'm thinking your looking to do this:http://us3.php.net/manual/en/function.arsort.php[/quote]arsort seems to be good if you want to sort the elements in the array like$myArray = array("b","a")after arsort becomes$myArray = array("a","b").But thats not my problem.I want to sort like this:.This array content:$myArray[0] = array("1","a")$myArray[1] = array("1","a")$myArray[2] = array("2","c")after sort will be$myArray[2] = array("2","c")$myArray[0] = array("1","a")$myArray[1] = array("1","b")In other words:$myArray[index] = array($sortedValue,$notSortedValue)$myArray[index] = array($sortedValue,$notSortedValue)$myArray[index] = array($sortedValue,$notSortedValue) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.