if(array_key_exists("USERS",$data)) { foreach($data["USERS"] as $idUser => $users) { foreach($users as $userId => $groups) { foreach($groups as $groupId => $contactType) { foreach($contactType as $typeIdContact => $contactOther) { foreach($contactOther as $idContact => $names) { foreach($names as $idName => $phones) { foreach($phones as $numberId => $otherContacts) { $nameValue = false; $numberValue = false; $value = false; if(array_key_exists("ID_CONTACT",$otherContacts)) { if($otherContacts["ID_CONTACT"] == "_delete") { $nameValue = "_delete"; } elseif($otherContacts["ID_CONTACT"] && $otherContacts["ID_CONTACT"] != "null" && array_key_exists("NUMBER_ID",$otherContacts) && $otherContacts["NUMBER_ID"] && $otherContacts["NUMBER_ID"] != "null") { $nameValue = $otherContacts["ID_CONTACT"]; $numberValue = $otherContacts["NUMBER_ID"]; } if(array_key_exists("ID_NUMBER",$otherContacts)) { $value = $otherContacts["ID_NUMBER"]; } } if($nameValue) { $nameKey = sprintf("CONTACT[%d][%d][%d][%d][%d][%d][%d][%s]",$idUser,$userId,$groupId,$typeIdContact,$idContact,$idName,$numberId,"ID_CONTACT"); $newData[$nameKey] = $nameValue; $newNewData[$nameKey] = $nameValue; } if($numberValue) { $nameKey = sprintf("CONTACT[%d][%d][%d][%d][%d][%d][%d][%s]",$idUser,$userId,$groupId,$typeIdContact,$idContact,$idName,$numberId,"NUMBER_ID"); $newData[$nameKey] = $numberValue; $newNewData[$nameKey] = $numberValue; } if($value !== false) { $nameKey = sprintf("CONTACT[%d][%d][%d][%d][%d][%d][%d][%s]",$idUser,$userId,$groupId,$typeIdContact,$idContact,$idName,$numberId,"ID_NUMBER"); $newData[$nameKey] = $value; $newNewData[$nameKey] = $value; } } } } } } } } }