i use 2 txt files , wanna asing 1 lines of txt1 to fist line of txt 2.
place.txt is as folow:
a
b
c
destination.txt is as folow:
brussels
paris
madrid
this the code i think should work:
<?php
$i= 0;
$fd = fopen ("place.txt", "r");
while (!feof ($fd)) {
$location[$i] = fgets($fd, 4096);
$i++;
}
$i= 0;
fclose ($fd);
$fd = fopen ("destination.txt", "r");
while (!feof ($fd)) {
$place[$i] = fgets($fd, 4096);
$i++;
}
fclose ($fd);
$result_des = array($location[0] => $place[0] , $location[1] => $place[1] ) ;
echo "The first line destination is {$result_des["a"]}.";
?>
result should be brussels
thanx for helping
why this script dont work? (the right place)
Moderator: General Moderators
how about doing it in one step?
Code: Select all
<?php $fdPlace = fopen ("place.txt", "r");
$fdDest = fopen ("destination.txt", "r");
while ( !(feof($fdPlace)||feof($fdDest)) )
$result_desїtrim(fgets($fdPlace, 4096))] = trim(fgets($fdDest, 4096));
fclose ($fdPlace);
fclose ($fdDest);?>- NetDragonX
- Forum Newbie
- Posts: 15
- Joined: Sat May 25, 2002 3:00 pm
- Location: Southern California
Hi.
Try this:
You're welcome 
Try this:
Code: Select all
<?php
$result_des = array($locationї0] => $placeї0], $locationї1]=>$placeї1]);
$g = 0;
while ( list( $locationї$g],$placeї$g] ) = each( $result_des ) )
{
echo $locationї$g]." - ".$placeї$g]."<br>";
$g++;
}
?>