我无法将表格数据正确保存到文件中。
但是有问题
我的代码
$find = $_POST['pole_1'];
$array = [];
$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);
// check array after read from file
print_r($array);
echo '<br />';echo '<br />';
// I check if it is in the array and if so I change the number
for( $i = 0; $i < count($array); $i++ ) {
if ($find === $array[$i]) {
echo "Match found"; echo '<br />';
$array[$i] = $array[$i] . '_code_use';
} else if ($find == ''){
echo "Empty field"; echo '<br />';
} else {
echo "Match NOT found"; echo '<br />';
}
}
// check array after changge
echo '<br />';
print_r($array);
// Saving to file
$file = 'new.txt';
for( $i = 0; $i < count($array); $i++ ) {
$data = $array[$i]."\n";
file_put_contents($file, $data);
}
文件Voucher.txt。 ->数组
01238
08752
09765
$ find ='08752'
循环后的数组,我希望将此保存到文件
01238
08752_code_use
09765