5
I’m not sure I can read a file .txt
and store your data in different positions in one array
.
The file is saved as follows:
city=A(100,80);
city=B(160,70);
city=C(110,50);
city=D(140,120);
city=F(155,40);
city=G(210,60);
city=H(190,10);
city=I(170,110);
route=A-C;140;
route=A-D;155;
route=C-F;125;
route=D-B;115;
route=D-I;152;
route=B-F;119;
route=B-G;136;
route=G-F;133;
route=F-H;163;
route=I-H;197;
And I’d like to read it and store it separately in the positions of a array
.
<?php
$f = fopen("mapa.txt", "r");
while (!feof($f)) {
$arrM = explode(";",fgets($f));
}
fclose($f);
?>
In this example, he is storing it all within a single position! And in case I’d like it to be stored like this:
$arrM[0] = city=A(100,80);
$arrM[1] = city=B(160,70);
$arrM[2] = city=C(110,50);
//.....
$arrM[] = route=A-C;140;
And what are the criteria? each file row in an array position?
– stderr
The criteria would be: $arrM[0] = city=A(100,80); $arrM[1] = city=B(160,70); $arrM[2] = city=C(110,50);
– Luiz Felipe