I have the following information in a txt
file.
500038;204932;61312;FTE GAV EDIT LACAVA TOTAL LARGXALTX15 GAV. NORMAL;LACA BLU FOSCO#996#335;5;78101922;xxxxxxx;0204932005
500038;204932;61312;FTE GAV EDIT LACAVA TOTAL LARGXALTX15 GAV. NORMAL;LACA BLU FOSCO#696#166;12;xxxxxxx;0204932012
100398;204932;50384;CJTO OPC LAT DIR/ESQ ARMARIO 30XALTXPROF;MDF BP LEGGERO#1040#340;74;78728780;xxxxxxx;0204932074
100398;204932;50385;CJTO OPC BASE SUP/INF RETA ARM LARGX30XPROF;MDF BP LEGGERO#769#340;71;78728777;xxxxxxx;0204932071
100398;204932;61108;FTE GAV EDIT ALCA LARGXALTX18 GAV. QUAD;LEGGERO#696#164;77;78728783;xxxxxxx;0204932077
100398;204932;50057;PAI OPC EDIT LARGXALTX15;LEGGERO#2610#100;39;78728745;xxxxxxx;0204932039
I took this information and stored it in array
.
After that, I just took the number of the orders and stored it in another array
.
$file_name = "IMP.txt";
$file = fopen("ArquivoOrig/".$file_name, "r") or die ("Arquivo não encontrado!");
$file_output = fopen("ArquivoImp/Output_".$file_name, "w") or die ("Arquivo não criado!");
while(!feof($file)){
$strAnalise = fgets($file);
$strAnaliseArray = explode(";", $strAnalise);
if(trim($strAnaliseArray[7]) != ''){
$ArrayChaveNome[$strAnaliseArray[1]] = trim($strAnaliseArray[7]);
}
$strArrayDados[] = $strAnaliseArray;
}
foreach ($strArrayDados as $key => $value) {
if(trim($value[7]) == ''){
if(array_key_exists($value[1], $ArrayChaveNome)){
$strArrayDados[$key][7]= $ArrayChaveNome[$value[1]];
}
}
}
for ($i=0; $i < count($strArrayDados); $i++) {
$arrayTemp[$i] = $strArrayDados[$i][0];
}
var_dump($arrayValor);
//Monta arquivo
foreach ($strArrayDados as $key => $value) {
$dataAtual = date('dmY');
fwrite($file_output, $dataAtual.";");
$resultPontoVirgulaToTxt = implode(";", $value);
fwrite($file_output, $resultPontoVirgulaToTxt);
}
fclose($file_output);
fclose($file);
I used the array_count_values
function to count the order numbers, with 2 requests with the number 500038
and 4 requests with the number 100398
.
$arrayValor = array_count_values($arrayTemp);
Return:
Array
(
[500038] => 2
[100398] => 4
)
Now the question is, how do I place these values next to the order number dynamically, because the order numbers can vary and the quantity too. This is what has to be in the txt
, does not print on the screen.
How do I stay:
2;500038;204932;61312;FTE GAV EDIT LACAVA TOTAL LARGXALTX15 GAV. NORMAL;LACA BLU FOSCO#996#335;5;78101922;xxxxxxx;0204932005
2;500038;204932;61312;FTE GAV EDIT LACAVA TOTAL LARGXALTX15 GAV. NORMAL;LACA BLU FOSCO#696#166;12;xxxxxxx;0204932012
4;100398;204932;50384;CJTO OPC LAT DIR/ESQ ARMARIO 30XALTXPROF;MDF BP LEGGERO#1040#340;74;78728780;xxxxxxx;0204932074
4;100398;204932;50385;CJTO OPC BASE SUP/INF RETA ARM LARGX30XPROF;MDF BP LEGGERO#769#340;71;78728777;xxxxxxx;0204932071
4;100398;204932;61108;FTE GAV EDIT ALCA LARGXALTX18 GAV. QUAD;LEGGERO#696#164;77;78728783;xxxxxxx;0204932077
4;100398;204932;50057;PAI OPC EDIT LARGXALTX15;LEGGERO#2610#100;39;78728745;xxxxxxx;0204932039