/**
 * Flattet nested arrays in eins.
 * @param array $array
 * @param array $newarray
 * @return array
 */
function flattenarray($array, &$newarray)
{
    foreach ($array as $index) {
        if (!is_array($index)) {
            $newarray[] = $index;
        } else {
            flattenarray($index, $newarray);
        }
    }
    return $newarray;
}
<?php

require_once 'template/header.php';
require_once 'template/navigation.php';
if (empty($_GET['id'])) {
    if (!empty($_SERVER['HTTP_REFERER'])) {
        header("Location: " . $_SERVER['HTTP_REFERER']);
    } else {
        header("Location: index.php");
    }
}
if (isset($_POST['delete'])) {
    $tasks = GetChilds($_GET['id']);
    $flattentasks = array();
    flattenarray($tasks, $flattentasks);
    foreach ($flattentasks as $index) {
        $sql = "DELETE FROM `tasks` WHERE `taskid` = " . $index;
        mysqli_query($con, $sql);
    }
    $comments = "DELETE FROM `comments` WHERE `taskid` = " . $_GET['id'];
    mysqli_query($con, $comments);
    $history = "DELETE FROM `statushistory` WHERE `taskid` = " . $_GET['id'];
    mysqli_query($con, $history);
    $sql = "DELETE FROM `tasks` WHERE `taskid` = " . $_GET['id'];
    mysqli_query($con, $sql);
    $sql = "DELETE FROM `recurring_tasks` WHERE `taskid` = " . $_GET['id'];
    mysqli_query($con, $sql);
}
if (!TaskExists($_GET['id'])) {
    header("Location: tasks.php");
    die;