【发布时间】:2016-07-02 17:45:28
【问题描述】:
我有数组 $commentArray 从文件中读取数据,它有像
some data1
some data2
...
--------------- (it's like a break point)
some data
some data
...
---------------
...
所以我在这里对我的数组做一些操作
for ($i = 0; $i < count($commentArray); $i++)
{
$arrayElem .= $commentArray[$i];
echo($arrayElem);
echo("<br>");
$arrayElem = "";
if($commentArray[$i] == "---------------")
{
/*
$commentArraySorted[$iterator] = $arrayElem;
$arrayElem = "";
$iterator++;
$i++;
*/
echo("STOP<br>");
}
}
但问题是编译器看不到字符串---------------,因为代码块
if($commentArray[$i] == "---------------")
{
/*
$commentArraySorted[$iterator] = $arrayElem;
$arrayElem = "";
$iterator++;
$i++;
*/
echo("STOP<br>");
}
不起作用,但是当我回显数组元素时,元素 --------------- 也在回显。
【问题讨论】:
-
如何从文件中填充 $commentArray?
-
$commentArray = file("recordsComment.txt"); -
添加第二个参数 -
FILE_IGNORE_NEW_LINES -
有帮助,非常感谢)