Re: Sort two coupled arrays [my solution]
| From: | tedd | Date: | Fri, 09 Apr 2010 13:44:41 +0000 |
| Subject: | Re: Sort two coupled arrays [my solution] | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303947@lists.php.net to get a copy of this message | ||
At 10:26 AM -0400 4/8/10, Robert Cummings wrote:
tedd wrote:Rob: You're never confused because you are always right. Congrats, you were the first to solve this problem this simply. To tell the truth, I didn't fully understand how array_multisort() worked until I reviewed your solution. I thought array_multisort() was to sort multi-dimensional arrays and simply overlooked the description that it could also sort several arrays at once. Duh -- sometimes my reading/comprehension skills suck. Many thanks for your time. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.comAt 8:28 AM -0400 4/8/10, Andrew Ballard wrote:On Wed, Apr 7, 2010 at 6:46 PM, Ryan Sun <ryansun81@gmail.com> wrote:Maybe I'm confused... but can't the following be used? <?phpAndrew: Half the solution is understanding the problem. However, the above solution only solves half the problem.rsort(array_combine(array2, array1)); you should expect array( 'Personal Email' => 75, 'USPS mail' => 40, 'Personal Phone' => 31, 'Web site' => 31, 'Text Message' => 31 ) logically, the items are your key but not the count of votesThat's the ticket. The solution is pretty simple now that we understand the nature of the problem. :-) Andrewarray_multisort( $votes, SORT_DESC, $items, SORT_DESC ); $final = array_combine( $items, $votes );print_r( $final );?> Cheers, Rob.