} else { $groupedData[$level][$node]["LiderType"] = "No Lider"; } } else { if ($persona["GP"] >= 1600) { $groupedData[$level][$node]["LiderType"] = "Indirect Lider"; } else { $groupedData[$level][$node]["LiderType"] = "No Lider"; } } } } } return $groupedData; } $groupedData = tag_liders($groupedData); function tag_underLider($groupedData) { $groupedData = array_reverse($groupedData); $bannedPerson = array(); foreach ($groupedData as $level => $levelNodes) { foreach ($levelNodes as $node => $persona) { if ($persona["LiderType"] == "Direct Lider") { array_push($bannedPerson, $persona["id"]); $groupedData[$level][$node]["underLider"] = true; } else { $bannedCount = 0; foreach ($bannedPerson as $key => $bannedId) { if ($persona["parent_id"] == $bannedId) { $bannedCount = $bannedCount + 1; }
$Data[$key]["isLider"] = false; } } return $Lideres; } function tag_liders($Data) { $Lideres = []; foreach ($Data as $key => $persona) { if ($persona["Level_Number"] == 1 and $persona["acumulado"] >= 1600) { $Data[$key]["isLider"] = true; } else { $Data[$key]["isLider"] = false; } } return $Data; } $lideres = search_liders($new_DATA); $new_DATA = tag_liders($new_DATA); $cantidadDeLideres = count($lideres); foreach ($new_DATA as $key => $persona) { foreach ($lideres as $llave => $value) { $new_DATA[$key]["sumar"] = true; $new_DATA[$key]["liderAmount"] = $cantidadDeLideres; if ($persona["id_grupo"] == $value) { $new_DATA[$key]["acumulado"] = 0; $new_DATA[$key]["sumar"] = false; } } } echo json_encode($new_DATA);