Learning to transfer array to view in Laravel5 framework

不言
Release: 2023-03-31 21:20:01
Original
1732 people have browsed it

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 }}

Copy after login

A concise way is this:

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

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!