1
I’m creating a system where you can add drugs by protocols. Ex: PROTOCOL NAME
    [ARRAY]
    NOME DO REMÉDIO
    [ARRAY 2]
    NOME DO ITEM        QUANTIDADE         TEMPO DE INFUSÃO [ARRAY] 
    NOME DO ITEM 2      QUANTIDADE 2       TEMPO DE INFUSÃO 2 [ARRAY]
    [ARRAY]
    NOME DE UM NOVO REMÉDIO
    NOME DO ITEM        QUANTIDADE         TEMPO DE INFUSÃO   [ARRAY]
    NOME DO ITEM 2      QUANTIDADE 2       TEMPO DE INFUSÃO 2 [ARRAY]
    NOME DO ITEM 3      QUANTIDADE 3       TEMPO DE INFUSÃO 3 [ARRAY]
I’m doing it this way:
$codigo = rand(5, 50000);
  // $codigo = uniqueAlfa(6);
  $itemA = $_POST['item'];
  $nomePres = $_POST['nome-item'];
   foreach ($itemA as $itemB):
     foreach (array($_POST['nome']) as $val1):
       foreach (array($_POST['tmp']) as $tmp):
    foreach (array($_POST['qtd']) as $val2):
      for ($i = 0; $i < count($val1); $i++):
        if($cadastra = $mysqli->query("INSERT INTO ifro_prescricao_medicamentos 
                  (id_prescricao, nome, item_padrao, item, quantidade, tempo_infusao) 
                  VALUES 
                 ('$codigo','$nomePres', '$itemB', '".$val1[$i]."', '".$val2[$i]."', '".$tmp[$i]."')")) {
          }  
        endfor;
      endforeach;
    endforeach;
  endforeach;
 endforeach;
But he’s always registering all the same items, not separating the names from the remedies
see the image: 

Follow the images on how is my information registration form:
This image is with only 1 medicine
This image already with 2 medicines

But it does not do the array inside each of them, I will send the photo of my form.
– Cristiano Facirolli
Follow the image link https://i.stack.Imgur.com/z8tOx.png
– Cristiano Facirolli
The variable
$codigois really necessary? one can not just change the columnid_prescricaoforAUTO INCREMENT?– teliz
Yes it is necessary, because I need to recover it later, like the prescription 1029 has item 1, 2, 3 with medicines 4, 6 , 7, understood?
– Cristiano Facirolli