if (count($filtered)) { //make sure that the parent points to the first sub
$parent[2] = array_values($filtered)[0][2];
}
with
if (count($filtered)) { //make sure that the parent points to the first sub
$filteredValues = array_values($filtered);
$parent[2] = $filteredValues[0][2];
}