0

我的PHP代码如下:

$file1 = 'file1.txt';
$file2 = 'file2.txt';
$files1 = fopen($file1,'r');
$files2 = fopen($file2,'r');
$title = "";    
while(!feof($files1)){
$data1 = explode(';', fgets($files1));
    while(!feof($files2)){
        $data2 = explode(';', fgets($files2));      

    }
    //I want to output $data2[0] in here
    //and want to make the calculation between $data1[0] - $data2[0]
    // The problem is that I can not use the $data1[0] outside the while loop of file2 that make me can not calculation.

}

我在代码中评论的问题。任何知道的人请帮助我,谢谢。

4

2 回答 2

0

因为 while 循环是嵌套的,所以您仍然可以$data1在您创建的 while 循环内使用$data2,因为它也在您定义的 while 循环内$data1

于 2013-01-15T06:19:09.267 回答
0
$file1 = 'file1.txt';
$file2 = 'file2.txt';
$files1 = fopen($file1,'r');
$files2 = fopen($file2,'r');
$title = "";    
while(!feof($files1)){
$data1 = explode(';', fgets($files1));
    while(!feof($files2)){
        $data2 = explode(';', fgets($files2));      
        $data2Array[]=$data2;
    }

     // You can use $data2Array[0] here now

    //I want to output $data2[0] in here
    //and want to make the calculation between $data1[0] - $data2[0]
    // The problem is that I can not use the $data1[0] outside the while loop of file2 that make me can not calculation.

}
于 2013-01-15T06:17:34.403 回答