Home>Article>Backend Development> Learning to transfer array to view in Laravel5 framework

Learning to transfer array to view in Laravel5 framework

不言
不言 Original
2018-06-13 10:04:56 1730browse

In the last article, we introduced how to transfer data to the view in the Laravel5 framework. Today we will study how to transfer array to the view. It is very detailed and is recommended for reference by friends in need.

We can not only send a data to the view, we can also send an Array

public function about() { return view('pages.about')->with([ 'first' => 'Zhang', 'last' => 'Jinglin' ]); } 

About {{ $first }} {{ $last }}

A concise way is this:

public function about() { $data = []; $data['first'] = 'Zhang'; $data['last'] = 'Jinglin'; return view('pages.about', $data); }

The result is the same, even simpler is Like this:

public function about() { $first = 'Zhang'; $last = 'Jinglin'; return view('pages.about', compact('first', 'last')); }

compact turns the parameters into arrays, and extract does the opposite. You can check the php manual to learn about compact and learn about extract by the way.

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Learning the model and controller of the Laravel 5 framework and the basic process of the view

The above is the detailed content of Learning to transfer array to view in Laravel5 framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn