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
$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 に答える
0

while ループは入れ子になっているため、$data1作成した while ループ内でも引き続き使用できます$data2。これは、定義した while ループ内でもあるためです。$data1

于 2013-01-15T06:19:09.267 に答える