在 Laravel 的刀片模板中显示数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24913348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:54:05  来源:igfitidea点击:

Display an array in a blade template from Laravel

arrayslaravelblade

提问by Lolo

I give an array to a view

我给一个数组一个视图

$data = array('data' => array(
                            'name' => 'Name',
                            'age' => 'Age'
                        )
);

return View::make('hello')->with('data', $data);

In the view.blade.php i'd like to do

在 view.blade.php 我想做

{{ $data['name'] }}

But it doesn't work.

但它不起作用。

回答by Laurence

You have an array inside of an array

你有一个数组里面的数组

{{{ $data['data']['name'] }}}

or change your array construction to

或将您的数组构造更改为

$data = array('name' => 'Name',
              'age' => 'Age');

then you can just do

那么你可以做

 {{{ $data['name'] }}}