【问题标题】:[] operator not supported for strings in wordpresswordpress 中的字符串不支持 [] 运算符
【发布时间】:2017-10-06 06:35:16
【问题描述】:

我在 WordPress 中有代码
我有错误 PHP Fatal error: [] operator not supported for strings in

$file1 = '';
 while (false !== ($file1 = readdir($dir2))) {
  if($file1 != "." && $file1 != "..") {
     $files[$item][] = $file1;
    }
 }  

我使用的是 php 5.4 版本。有什么想法吗?

【问题讨论】:

  • $files[$item] 是一个字符串,而不是一个数组。 3v4l.org/GXuXg

标签: php wordpress


【解决方案1】:

readdir() 接受文件句柄,而不是字符串:

引用manual:

目录句柄: 先前使用opendir() 打开的目录句柄资源。如果没有指定目录句柄,则假定为opendir()打开的最后一个链接。`

所以也许先使用opendir()

【讨论】:

    猜你喜欢
    • 2017-07-02
    • 1970-01-01
    • 2010-09-17
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2010-12-12
    相关资源
    最近更新 更多