相关疑难解决方法(0)

刀片php中的Laravel打印阵列

我想在我的.blade.php中显示一个数组,但它无法正常工作,所以我的控制器看起来像这样:

class WatchController extends Controller
{

    public function index()
    {
        $watchFolderPath = 'C:\\xampp\\htdocs\\Pro\\rec\\';
        $watchFolder     = $this->dirToArray($watchFolderPath);
        return view('watch.new')->with('watchFolder', $watchFolder);
    }

    # Get Directories of Path as Array
    function dirToArray($dir) {

        $result = array();

        $cdir = scandir($dir);

        foreach ($cdir as $key => $value)
        {
            if (!in_array($value,array(".","..")))
            {
                if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
                {
                    $result[$value] = $this->dirToArray($dir . DIRECTORY_SEPARATOR . $value);
                }
                else
                {
                    $result[] = $value;
                }
            }
        }
        return $result;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的刀片中,我只是试着这样称呼它:

{{ $watchFolder }}
Run Code Online (Sandbox Code Playgroud)

但它没有用,我收到以下错误:

htmlentities()期望参数1为字符串,给定数组

编辑:我得到的数组显示目录中包含子文件夹的所有文件夹/文件.(用过dd()) …

php arrays laravel blade

9
推荐指数
4
解决办法
5万
查看次数

标签 统计

arrays ×1

blade ×1

laravel ×1

php ×1