0

I am new to the use of arrays in anything more than a simple context. I have researched and experimented with usort, uasort multisort and ksort even php7 spaceships over the last 2-3 hours to solve this problem - but I keep getting errors and am confused about the best (simplest) approach. I would post everything I have tried - but honestly it would fill the entire page. Undoubtedly, my lack of experience with arrays. I just need help with a simple method to Sort in ascending order numeric order by the second level of a multi level indexed array (as shown below - ie from $input to $output). Thank you

$input = array
        (
            array(9,1110),
            array(10,111),
            array(8,100),
            array(7,200),
            array(6,690),
            array(11,222)
        );


$output = array
        (
        array(6,690),
        array(7,200),
        array(8,100),
        array(9,1110),
        array(10,111),
        array(11,222)       

    );
WChris
  • 71
  • 1
  • 12
  • Can you post any of your attempts please? This is fairly straightforward, and you probably weren't far off. It'll be more helpful in the long-run if we can help debug your code rather than just providing an answer, – iainn Nov 27 '17 at 15:33
  • If you used usort, remember that it takes the array by reference, so it won't be `$output = usort($input, ...`. `$input` itself will be sorted. – Don't Panic Nov 27 '17 at 15:35
  • @iain sure. I started with array_multisort($input([ ][0]).That was no good. I ended up with usort but my problem here is how to generaste and apply the function to the sort required. I do think this is the right approach from what I have read. But I cant get my head around how to write the function and apply it to the sort on a numeric array. – WChris Nov 27 '17 at 16:04

0 Answers0