开发者

array_reverse() expects parameter 1 to be array, string given in

开发者 https://www.devze.com 2023-03-13 13:17 出处:网络
I am grabbing a .txt file and trying to reverse it, but I get this error when I try to, I don\'t understand it. Help please?

I am grabbing a .txt file and trying to reverse it, but I get this error when I try to, I don't understand it. Help please?

array_reverse() expects parameter 1 to be array, string given in ......

Here is the code:

$dirCont = file_get_contents($dir, NULL, NULL, $sPoint, 10240000)开发者_如何学Go;
$invertedLines = array_reverse($dirCont);

echo $invertedLines;


A string is not an array? Even if it were (as in C strings) it would not work as you expected. You'll need to split the file on line breaks (if you're trying to reverse to get the end of the file first).

$invertedLines = array_reverse(preg_split("/\n/", $dirCont));


I think you need to pass the value on an array.

array_reverse(array($dircont));

This is working fine for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消