Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7867455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:43:18+00:00 2026-06-03T00:43:18+00:00

I just asked this question a moment ago but I asked incorrectly so I

  • 0

I just asked this question a moment ago but I asked incorrectly so I apologize.

I’m hoping there’s an easy way to do this without tons and tons of loops.

I have a matrix in the following manner:

      Foo1    Foo2    Foo3 ....   FooN
Jan    1       8       5            4
Feb    10      12      15          11
Mar    12      7       4            3
Apr    10      16      7           17

Assuming the following array:

$arrayMonths = array(
       'jan' => array(1, 8, 5,4)
       'feb' => array(10,12,15,11)
       'mar' => array(12, 7, 4, 3)
       'apr' => array(10,16,7,17)
    );

I need to sort the above array and show it in the following manner:

array[apr][FooN] = 17
array[feb][Foo3] = 15
array[mar][Foo1] = 12
array[jan][Foo2] = 8

Essentially, I need to get the greatest sum of the above weights, one month can only have one foo and one foo can only have one month. In the above example, the result would be 52.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:43:19+00:00Added an answer on June 3, 2026 at 12:43 am

    See Demo : http://codepad.org/vDI2k4n6

    $arrayMonths = array(
           'jan' => array(1, 8, 5,4),
           'feb' => array(10,12,15,11),
           'mar' => array(12, 7, 4, 3),
           'apr' => array(10,16,7,17),
        );
    
    $position = array("Foo1","Foo2","Foo3","FooN");
    $set = array();
    
    foreach($arrayMonths as $key => $value)
    {
        $max = max($value);
        $pos = array_search($max, $value);
        $set[$key][$position[$pos]] = $max ;
    }
    
    
    function cmp($a, $b)
    {
        foreach($a as $key => $value )
        {
            foreach ($b  as $bKey => $bValue)
            {
                return $bValue - $value ;
            }
        }
    
    }
    
    uasort($set,"cmp");
    var_dump($set);
    

    Output

        array
          'apr' => 
            array
              'FooN' => int 17
          'feb' => 
            array
              'Foo3' => int 15
          'mar' => 
            array
              'Foo1' => int 12
          'jan' => 
            array
              'Foo2' => int 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just asked this question an hour ago but with regards to IE8
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I just asked this question: Are there ways to get android app view hierarchy
I asked this question yesterday, and at the time it was just what I
I know this has been asked thousands of times but I just can't find
I know this has been asked different ways several times, but I'm just not
I know this has been asked before, but I just cant seem to find
This has already been asked here , but I am just not satisfied with
I've asked about this earlier but the question itself and all the information in
I just asked this question . In short, when you throw from a win32

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.