Hi,
I have been trying to sort this out all day and still haven't managed to come up with a solution. I really hope someone here will be able to help.
I have got a multi-level array, which has a structure for categories and parent categories. I want to sort the array so that I can produce an alphabeticallly listed flat tree menu, but try as I might I can't come up with a solution. I need it to work with any entries that have a parent child relationship, but below is the test array I am trying to work on along with the format of the desired result.
I would be eternally grateful if anyone can come up with a solution.
The Problem Test Array
$Loc[0]= array("Name" => "England", "Cat_id" => "001", "Parent_id" => 000", "Level" => "1", "Num_Children" => "6");
$Loc[1]= array("Name" => "Nottinghamshire", "Cat_id" => "001-001", "Parent_id" => 001", "Level" => "2", "Num_Children" => "3");
$Loc[2]= array("Name" => "Nottingham", "Cat_id" => "001-001-001", "Parent_id" => 001-001", "Level" => "3", "Num_Children" => "2");
$Loc[3]= array("Name" => "Park Plaze", "Cat_id" => "001-001-001-001", "Parent_id" => 001-001-001", "Level" => "4", "Num_Children" => "");
$Loc[4]= array("Name" => "Buggy Land 2", "Cat_id" => "001-001-001-002", "Parent_id" => 001-001-001", "Level" => "4", "Num_Children" => "");
$Loc[5]= array("Name" => "Worksop", "Cat_id" => "001-001-002", "Parent_id" => 001-001", "Level" => "3", "Num_Children" => "");
$Loc[6]= array("Name" => "Bingham", "Cat_id" => "001-001-004", "Parent_id" => 001-001", "Level" => "3", "Num_Children" => "");
$Loc[7]= array("Name" => "Greater Manchester", "Cat_id" => "001-002", "Parent_id" => 001", "Level" => "2", "Num_Children" => "2");
$Loc[8]= array("Name" => "Manchester", "Cat_id" => "001-002-001", "Parent_id" => 001-002", "Level" => "3", "Num_Children" => "");
$Loc[9]= array("Name" => "Stockport", "Cat_id" => "001-002-005", "Parent_id" => 001-002", "Level" => "3", "Num_Children" => "");
$Loc[10]= array("Name" => "Leicestershire", "Cat_id" => "001-004", "Parent_id" => 001", "Level" => "2", "Num_Children" => "1");
$Loc[11]= array("Name" => "Leicester", "Cat_id" => "001-004-001", "Parent_id" => 001-004", "Level" => "3", "Num_Children" => "");
$Loc[12]= array("Name" => "Hampshire", "Cat_id" => "001-007", "Parent_id" => 001", "Level" => "2", "Num_Children" => "");
$Loc[13]= array("Name" => "Sussex", "Cat_id" => "001-009", "Parent_id" => 001", "Level" => "2", "Num_Children" => "1");
$Loc[14]= array("Name" => "Brighton", "Cat_id" => "001-009-001", "Parent_id" => 001-009", "Level" => "3", "Num_Children" => "1");
$Loc[15]= array("Name" => "Royal Albion", "Cat_id" => "001-009-001-001", "Parent_id" => 001-009-001", "Level" => "4", "Num_Children" => "");
$Loc[16]= array("Name" => "Nothamptonshire", "Cat_id" => "001-010", "Parent_id" => 001", "Level" => "2", "Num_Children" => "1");
$Loc[17]= array("Name" => "Northampton", "Cat_id" => "001-010-001", "Parent_id" => 001-010", "Level" => "3", "Num_Children" => "");
$Loc[18]= array("Name" => "Scotland", "Cat_id" => "002", "Parent_id" => 000", "Level" => "1", "Num_Children" => "2");
$Loc[19]= array("Name" => "Scottish Highlands", "Cat_id" => "002-001", "Parent_id" => 002", "Level" => "2", "Num_Children" => "");
$Loc[20]= array("Name" => "Scottish Midlands", "Cat_id" => "002-003", "Parent_id" => 002", "Level" => "2", "Num_Children" => "2");
$Loc[21]= array("Name" => "Glasgow", "Cat_id" => "002-003-001", "Parent_id" => 002-003", "Level" => "3", "Num_Children" => "");
$Loc[22]= array("Name" => "Edinburgh", "Cat_id" => "002-003-002", "Parent_id" => 002-003", "Level" => "3", "Num_Children" => "");
$Loc[23]= array("Name" => "Wales", "Cat_id" => "003", "Parent_id" => 000", "Level" => "1", "Num_Children" => "");
The Desired Result
=> England
=> => Greater Manchester
=> => => Manchester
=> => => Stockport
=> => Hampshire
=> => Leicestershire
=> => => Leicester
=> => Nothamptonshire
=> => => Northampton
=> => Nottinghamshire
=> => => Bingham
=> => => Nottingham
=> => => => Buggy Land 2
=> => => => Park Plaze
=> => => Worksop
=> => Sussex
=> => => Brighton
=> => => => Royal Albion
=> Scotland
=> => Scottish Highlands
=> => Scottish Midlands
=> => => Edinburgh
=> => => Glasgow
=> Wales