【问题标题】:Can't copmare strings PHP [duplicate]无法比较字符串PHP [重复]
【发布时间】: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
  • 有帮助,非常感谢)

标签: php arrays string


【解决方案1】:

感谢 splash58。答案是在$commentArray = file("recordsComment.txt"); 中添加第二个参数FILE_IGNORE_NEW_LINES

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2013-01-03
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    相关资源
    最近更新 更多