Re: Sort two coupled arrays {my solution]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 7, 2010 at 6:46 PM, Ryan Sun <ryansun81@xxxxxxxxx> wrote:
> On Wed, Apr 7, 2010 at 6:29 PM, tedd <tedd.sperling@xxxxxxxxx> wrote:

[snip]

>>
>> Let's look at the problem again (a vote collection problem):
>>
>> Array 1
>> (
>>    [1] => 75
>>    [2] => 31
>>    [3] => 31
>>    [4] => 31
>>    [5] => 40
>> )
>>
>> Array 1 is an array that contains the count of votes ($votes[] ) for the
>> index. IOW, index 1 received 75 votes.
>>
>> Array 2
>> (
>>    [1] => Personal Email
>>    [2] => Personal Phone
>>    [3] => Web site
>>    [4] => Text Message
>>    [5] => USPS mail
>> )
>>
>> Array 2 is an array that contains the names for the items ($items[] ) voted
>> upon. As such, index 1 (Personal Email) received 75 votes.
>>
[snip]
>
> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux