sorting doesn't sort?

From: Håvard Olerud Eriksen (hereriks_at_PANTSyahoo.com)
Date: 06/30/04


Date: Wed, 30 Jun 2004 13:02:38 +0200

I've got an array of arrays that I need to sort on preferably one of the
indices of the nested array, keeping the order of the outside array. The
structure is like this:

array([i] => array(key["name"] => data)
and what I need to do is to sort the nested array alphabetically according
to key["name"].
I can either use the name property of the nested array as index for the
outside array (then I need to keep the relationship between the outside
array and the nested array, or use a numeric index thus making the
relationship between the outside and nested array irrellevant.) What I need
to do in any case is to sort the nested array. I've tried using
arsort($array, SORT_STRING) but for some reason this doesn't sort the array
the way that I expected.

Can anyone help me out?

A var_dump of one element of the outside array looks like this:
array(2)
{ [1]=> array(2)
 { ["id"]=> string(1) "1" ["name"]=> string(6) "JustforShow" }
{ [2]=> array(2)
 { ["id"]=> string(1) "1" ["name"]=> string(6) "Testing" }

etc.



Relevant Pages

  • Re: help with recursive function
    ... I've upgraded PHP to version 5 and both your code and the old code on that website work beautifully. ... // output array structure for debugging ... SELECT id, parent, name ... // fetch the data into a nested array structure ...
    (comp.lang.php)
  • Re: Hash Sorting
    ... Ilan Berci wrote: ... hash of arrays into an array of arrays where the second arrays is ... my exact code that doesn't work: ... doing this I expect pi_array_sorted to be a nested array, sorted by key, ...
    (comp.lang.ruby)
  • Re: Cloning arrays
    ... puts "The ID of a is #" ... change the corresponding element of the other array (because they contain the ... If your array is a nested array, things become more complicated, as ... Marshalling - not enough time to keep up with the newsgroup. ...
    (comp.lang.ruby)
  • Re: Sort hashes using values
    ... How do I sort this by the values? ... Converts hsh to a nested array of arrays and sorts it, ...
    (comp.lang.ruby)
  • Indented text converted to arrays of arrays
    ... and convert it into a nested array of arrays like the following: ... that level and $a->is an array ref to the next level. ... The indenting is regular, the levels may be arbitrarily deep, and no ... Brad ...
    (comp.lang.perl.misc)