Jag löste det genom att lägga till en parameter till identeringsfunktionen. Tack för hjälp .
PHP-kod:
function intendChildren($children, $growth) {
foreach($children as $row) {
$intend = "";
for($i=0;$i<$growth;$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"], ($growth+1));
}
}
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"], 1);
}