php - 在 PHP 中将数组与字符串进行比较时,如果条件为假
问题描述
我有一个 FOR 循环和一个 IF 语句,用于检查 txt 文档中的每一行是否有某个单词。但是,当循环到达包含值“header”的行时,IF 语句不认为这是真的。
txt 文件
header
bods
#4f4f4f
30
100
1
text
this is content for the page
#efefef
10
300
2
img
file/here/image.png
300
500
filler
3
header
this is header text
#4f4f4f
30
100
4
.php 文件
$order = array();
$e = 0;
$h = 0;
$headerCount = 0;
$textCount = 0;
$imgCount = 0;
//Open file putting each line into an array
$textFile = fopen("test.txt","r+");
$inTextFile = fread($textFile, filesize("test.txt"));
$arrayFile = explode("\n", $inTextFile);
$arrayFileSize = sizeof($arrayFile);
$elementCount = $arrayFileSize / 6;
for ($x = 0; $x < $arrayFileSize; $x++) {
if ($arrayFile[$x] == "header") {
echo $x;
echo " Yes : ".$arrayFile[$x] . "<br>";
$headerCount++;
}
else {
echo $x;
echo " No : " . $arrayFile[$x] . "<br>";
}
}
解决方案
推荐阅读
- c++ - std::mutiset vs std::vector.Getting TLE in a code but AC in another
- typescript - 如何在 Typescript 中创建具有 Type1 的所有属性或 Type2 的所有属性的类型?
- javascript - OAuth2 - 在数据库中存储什么?
- java - 忽略特殊字符的单词使用计数器
- python - 如何在 Tensorflow 2 中使用 tf.keras.utils.Sequence 和 model.fit()?
- python - 有什么方法可以从网格中的标签中获取文本,只有 tkinter 中的行和列
- firebase - 如何在不登录的情况下通过存储在 Firebase Firestore 中的用户名获取用户配置文件数据?扑
- c# - 删除元素 ASP.Net Core MVC 的问题
- flutter - Flutter:更改状态栏文本颜色无法正常工作
- angular - 错误 TS2345:“事件”类型的参数不可分配给“字符串”类型的参数