Re: Sort two coupled arrays {my solution]

From: Date: Thu, 08 Apr 2010 14:26:05 +0000
Subject: Re: Sort two coupled arrays {my solution]
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-303902@lists.php.net to get a copy of this message
tedd wrote:
At 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:
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 votes
That's the ticket. The solution is pretty simple now that we understand the nature of the problem. :-) Andrew
Andrew: Half the solution is understanding the problem. However, the above solution only solves half the problem.
Maybe I'm confused... but can't the following be used? <?php
    array_multisort( $votes, SORT_DESC, $items, SORT_DESC );
    $final = array_combine( $items, $votes );
    print_r( $final );
?> Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#303902) next »