Laravel print array in blade php
我想在我的.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;
}
}
在我的刀片里,我只是试图这样称呼它:
{{ $watchFolder }}
但它不起作用,我得到以下错误:
htmlentities() 期望参数 1 是字符串,给定数组
编辑:我得到的数组显示目录中带有子文件夹的所有文件夹/文件。(使用 dd())
目前它看起来像这样:
array:6 [▼
123123 => array:2 [▼
"subfolder1" => array:1 [▼
0 => "video.mpg"
]
"subfolder2" => array:1 [▶]
]
789 => array:2 [▶]
"folder1" => array:2 [▶]
"folder2" => array:2 [▶]
"folder3" => array:2 [▶]
"folder1" => []
]