1

I want to sort these arrays and put the highest percentage values first. I keep getting errors when I try it such as uneven arrays so I unset the [status] key because I actually dont need it and it is still not working for me.

Here is the array I am trying to sort:

Array
(
    [position] => RB
    [name] => Stewart, Jeremy
    [team] => OAK
    [percent] => 3.15
)
Array
(
    [position] => RB
    [name] => Stewart, Jeremy
    [team] => OAK
    [percent] => 3.15
)
Array
(
    [status] => R
    [position] => QB
    [name] => Smith, Geno
    [team] => NYJ
    [percent] => 2.67
)
Array
(
    [status] => R
    [position] => QB
    [name] => Smith, Geno
    [team] => NYJ
    [percent] => 2.67
)

Here is my code:

       foreach( $dropsOutput as $key => $category ) { 
          unset($category['id']);
          //unset($category['status']);

         if (array_key_exists("percent", $category)) { 
           foreach( $category as $index => $value ) { 

             echo "<pre>"; 
             print_r($category);
             echo "</pre>";                   
           }  
         }                    
       }
Kustom
  • 181
  • 3
  • 15
  • Have you got four separate arrays or one array of arrays? – Dale Aug 31 '13 at 16:53
  • 1
    Your code does not contain a call to `array_multisort` but your questions title suggests that. How come? - And I already now point you to a PHP 5.5 function called `array_column`. It is most likely very useful in your case, in case you don't have 5.5, see http://stackoverflow.com/a/11558780/367456 – hakre Aug 31 '13 at 16:54
  • Dale, its one array of arrays, sorry that would be helpful. -hakre I only have php 5.3 available. I did try array_multisort but it wasnt working so I erased my code and tried several other things with no good result. I will see your link and see what I can find. – Kustom Aug 31 '13 at 17:06
  • -hakre That was more focused on counting a specific number of an item not sorting inside on a multidimensional array, I dont see how that will help me but thanks anyways:) – Kustom Aug 31 '13 at 17:25

0 Answers0