我对编程很熟悉,但我面临的有点奇怪。if 语句仅适用于最后一次迭代:
输出: IN IN OUT OUT OUT OUT IN OUT IN BIN BOUT OUT OUT OUT OUT
但是,如果我添加一个 if 语句,它只会在最后一次迭代中执行:
<?php
$conn = mysqli_connect('localhost','root','','text');
if(!$conn)
{
die(mysqli_error());
}
$open = fopen('test.txt','r');
while (!feof($open))
{
$getTextLine = fgets($open);
$explodeLine = explode(",",$getTextLine);
list($Date,$ID,$Status) = $explodeLine;
if($Status == "OUT"){
echo "$Status";
}
}
fclose($open);
?>
输出:输出
文本文件:
19-04-21 13:41:38 ,0000000917 ,IN
19-04-21 13:49:50 ,0000001310 ,IN
19-04-21 13:52:24 ,0000000505 ,OUT
19-04-21 13:53:36 ,0000000546 ,OUT
19-04-21 14:05:24 ,0000001267 ,OUT
19-04-21 14:05:32 ,0000001228 ,OUT
19-04-21 14:06:26 ,0000000454 ,IN
19-04-21 14:13:10 ,0000000990 ,OUT
19-04-21 14:17:32 ,0000001354 ,IN
19-04-21 14:27:04 ,0000000325 ,BIN
19-04-21 14:27:18 ,0000000325 ,BOUT
19-04-21 14:31:12 ,0000000649 ,OUT
19-04-21 14:32:22 ,0000000061 ,OUT
19-04-21 14:33:00 ,0000001301 ,OUT
19-04-21 14:34:34 ,0000000548 ,OUT