I have an array where each element contains an array that in turn contains 2 numbers indexed by "id" and "parent".
Every id except for the first one belongs to another, its parent. What I want to do now is sort the array so that every id is put after its parent starting with id 1. Example: arr1 = ( 0 => array("id" => 1, "parent" => 0), 1 => array("id" => 2, "parent" => 1), 2 => array("id" => 3, "parent" => 1), 3 => array("id" => 4, "parent" => 2), 4 => array("id" => 5, "parent" => 3), 5 => array("id" => 6, "parent" => 2), 6 => array("id" => 7, "parent" => 1), 7 => array("id" => 8, "parent" => 4), 8 => array("id" => 9, "parent" => 5) ) In other words they are in the following order.. 1=0 2=1 3=1 4=2 5=3 6=2 7=1 8=4 9=5 After the sort I want them to be in the following order.. 1=0 2=1 4=2 8=4 6=2 3=1 5=3 9=5 7=1 Note that id 6 isn't placed right after id 4 since id 4 has parents of its own which have precedence. An easier way to illustrate this would be by indenting the list.. 1=0 2=1 4=2 8=4 6=2 3=1 5=3 9=5 7=1 The index of $arr1 makes no difference so the array can be shifted or rebuilt.. If you are wondering I need this for a forum that im building. If you have any suggestions as how to do this better feel free to tell me all about it :) Thanks in advance. // Leif Högberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php