Nu har jag lyckats att få den array jag vill ha. Här är koden:
	PHP-kod:
	
		
			
$ordered_categories = array();
    $i = 0;
    foreach($categories as $k => $v) {
        // Loop only parents and put in fresh list
        if($v["parent"] == 0) {
            $ordered_categories[$i] = $v;
            $ordered_categories[$i]["children"] = getSortedCategories($v["id"], $categories);
            $i++;
        }
    }
    
    function getSortedCategories($id, $categories) {
        $return = array();
        $m = 0;
        foreach($categories as $c) {
            if($c["parent"] == $id) {
                $return[$m] = $c;
                $return[$m]["children"] = getSortedCategories($c["id"], $categories);
            }
            $m++;
        }
        return $return;
    } 
		
	
 Men nu har jag problem med att få rätt identering i <select> taggen. Jag vill att varje barn hoppar in 5   och varje barnbarn hoppar in det dubbla(10  

. Men jag vet inte 
när jag ska öka 
$treeGrowth för att den ska identera rätt. Här är mitt försök. Denna kod identerar bara de första barnen(alltså nivå 1)
	PHP-kod:
	
		
			
<select name="parent"><option value="0">Ingen</option>
                                <?php
                                    
                                    function intendChildren($children) {
                                        $treeGrowth = 1;
                                        foreach($children as $row) {
                                            $intend = "";
                                            for($i=0;$i<$treeGrowth;$i++) {
                                                $intend .= "     ";
                                            }
                                            echo '<option '.((isset($_SESSION["last_parent_category"]) && $_SESSION["last_parent_category"] == $row["id"]) ? 'selected' : '').' value="'.$row["id"].'">'.$intend.'|__'.$row["name"].'</option>';
                                            intendChildren($row["children"]);
                                        }
                                    }
                                
                                    foreach($ordered_categories as $row) {
                                        echo '<option '.((isset($_SESSION["last_parent_category"]) && $_SESSION["last_parent_category"] == $row["id"]) ? 'selected' : '').' value="'.$row["id"].'">|__'.$row["name"].'</option>';
                                        intendChildren($row["children"]);
                                    }
                                ?>
                                </select>
		
	
 EDIT: Bry er inte om SESSION. Den lade jag bara till för att jag är lat(den hjälper mig när jag lägger till nya underkategorier.)