[英]Laravel foreach only returns first value
First please be gentle i am a beginner and only prectising, 首先请温柔我是一个初学者,只有prectising,
I have a problem, i would like to get laravel's language files and edit their content. 我有一个问题,我想获得laravel的语言文件并编辑其内容。
My problem is what i dont really understand is the following 我的问题是我真正理解的是以下内容
i have a functions what returns the actual files, i have a variable what stores this 我有一个函数返回实际文件,我有一个变量存储这个
$directory = File::files(self::$lang_path.$code);
id i die and dump i get back the following 我死了,转储我回来了以下
array(3) {
[0]=>
string(26) "app/lang/en/pagination.php"
[1]=>
string(25) "app/lang/en/reminders.php"
[2]=>
string(26) "app/lang/en/validation.php"
}
all fine, but if foreach
it and die and dump 一切都很好,但是如果foreach
它并且死亡和倾倒
$directory = File::files(self::$lang_path.$code);
foreach ($directory as $files)
{
dd($files);
}
i just get back string(26) "app/lang/en/pagination.php"
我刚回到string(26) "app/lang/en/pagination.php"
could please tell me what i am doing wrong? 请告诉我我做错了什么?
and the problem is i need it because i will need nested foreac 问题是我需要它,因为我需要嵌套的foreac
like 喜欢
$directory = File::files(self::$lang_path.$code);
foreach ($directory as $files)
{
foreach ($files as $file)
{
// preform more stuff
}
}
and idont understand what iam doing wrong, could please someone give me a hint? 并且idont明白我做错了什么,能不能有人给我一个提示?
The dd
(dump and die) function kills script execution - It therefore will only show the first item in the array before calling die()
. dd
(dump和die)函数会杀死脚本执行 - 因此它只会在调用die()
之前显示数组中的第一项。
Use var_dump
instead. 请改用var_dump
。
If you're curious, you can see the function definition here . 如果你很好奇,可以在这里看到功能定义 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.