1
I have the information below in a file txt
.
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 a array
.
After that I took only the order number and stored 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 function array_count_values
to count order numbers, with 2 orders with the number 500038
and 4 applications under 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, as the order numbers may vary and the quantity also. That’s what has to be in txt
, do not print on screen.
How I need you to 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
Before storing I already gave one
explode
on boundaries which are;
. I forgot to mention it. That’s why it came out like thisArray
(
 [500038] => 2
 [100398] => 4
)
– KevinF
@Kevin. F then puts the code in the question so that we can understand, please
– Guilherme Nascimento
His answer did not give the answer to me but I managed to do, his answer cleared things up.
– KevinF
@Kevin. F did not work because the example in your question is incomplete, if put complete I will be able to formulate it the way you need. Your updated example keeps coming out different
– Guilherme Nascimento
So I put all my code and all the information you have on
txt
see if you’re better now to understand.– KevinF
@Kevin. F is now better, I’ll try to adjust the example.
– Guilherme Nascimento