Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从文件中删除表中的记录_Php_Arrays - Fatal编程技术网

Php 从文件中删除表中的记录

Php 从文件中删除表中的记录,php,arrays,Php,Arrays,我从文件中下载了数据并将其保存到表中,然后尝试搜索数组,如果它在表中,则写入“Match found”,如果不写入“Match not found” 我的文件凭证.txt ub65rf 98huf4 YbyR42 我的PHP代码 $array = []; $array = file('voucher.txt'); $find = '98huf4'; if (in_array($find, $array)) { echo "Match found"; } else {

我从文件中下载了数据并将其保存到表中,然后尝试搜索数组,如果它在表中,则写入“Match found”,如果不写入“Match not found”

我的文件凭证.txt

ub65rf
98huf4
YbyR42
我的PHP代码

$array = [];
$array = file('voucher.txt');

$find = '98huf4';


if (in_array($find, $array))
  {
  echo "Match found";
  }
else
  {
  echo "Match not found";
  }
默认情况下,
file()
在字符串中包含换行符,因此它们与
$find
字符串不匹配。有一面旗子可以移除它们

$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);
默认情况下,
file()
在字符串中包含换行符,因此它们与
$find
字符串不匹配。有一面旗子可以移除它们

$array = file('voucher.txt', FILE_IGNORE_NEW_LINES);