Foreword
Collection by Illuminate \ Support \ Collection instance, most of the kernel parameters passed Laravel have used the collection, but this does not mean that the collection is good. Laravel as a quick and elegant development framework, there is some truth in his lies, not because of his route, DB, listeners and so on. When you need to handle an array of arrays, you may need it to help you quickly solve practical problems.
Create Collection
$collection = collect([1, 2, 3]);
Obviously, this is a very simple operation, please come to a halt you want to say, "This operation is very complicated," then it is more similar to early versions of the statement PHP5.x way.
$collection
= array(1,2,3);
laravel for the collection did not do any complex matter, will thank you in the "Source collection Laravel resolve the" next chapter,
Fight back to the prototype
If you want to convert a set of data, its use is also very simple
collect([1, 2, 3])->all();
------>
[1, 2, 3]
However, in the case of properties under consideration can be used Laravel collection, after all, it will help you complete the job array operations of ninety percent.
For example, we need to set the score cut by a horizontal line, divided into two or more in number and array. Jiang Zi can do using a collection of ~
$collection = collect([1, 2, 3, 4, 5, 6, 7]);
$chunks = $collection->chunk(4);
$chunks->toArray();
// [[1, 2, 3, 4], [5, 6, 7]]
According to the method and some also query sql statement to design, let's look at what are the specific bar.
Method List
Here are some common set of methods of operation, and all your specific operation official.
Acknowledgments
Thank you see here, hope Benpian be able to help you. Thank you, do not pay close attention to the next set of exercises?
Learn more information, please visit:
Above hope to help everyone, many PHPer always encounter some problems and bottlenecks in the advanced time, write more business code no sense of direction, I do not know from where to start to ascend, which I compiled some information, including but not limited to: a distributed architecture, highly scalable, high-performance, high-concurrency, server performance tuning, TP6, laravel, YII2, Redis , Swoole, Swoft, Kafka, Mysql optimization, shell scripts, Docker, micro-services, Nginx, etc. more advanced knowledge required for advanced dry goods can be free for everyone to share , need to be added to my official group here .