我有以下代码可以从文件中读取,并在一些计算后写回它。
if(file_exists(CACHE_FILE_PATH)) {
//read the cache and delete that line!
$inp = array();
$cache = fopen(CACHE_FILE_PATH, 'r');
if($cache) {
while(!feof($cache)) {
$tmp = fgets($cache);
//some logic with $tmp
$inp[] = $tmp;
}
fclose($cache);
}
var_dump($inp);
$cache = fopen(CACHE_FILE_PATH, 'w');
var_dump($inp);
if($cache) {
var_dump($inp);
foreach ($inp as $val) {
echo "\nIN THE LOOP";
fwrite($val."\n");
}
fclose($cache);
}
}
var_dumps 的输出是:
array(3) {
[0]=>
string(13) "bedupako|714
"
[1]=>
string(16) "newBedupako|624
"
[2]=>
string(19) "radioExtension|128
"
}
array(3) {
[0]=>
string(13) "bedupako|714
"
[1]=>
string(16) "newBedupako|624
"
[2]=>
string(19) "radioExtension|128
"
}
array(3) {
[0]=>
string(13) "bedupako|714
"
[1]=>
string(16) "newBedupako|624
"
[2]=>
string(19) "radioExtension|128
"
}
即使它是一个数组,它也不会进入循环和打印IN THE LOOP
!为什么?