In this post we will learn how can merge array in inside array in single array, Using laravel helper function we will merge array in side array in\to single array, this function providing by laravel.
Some time developer need to merge multidimensional array in to single array or multiple array in single array.
Using Arr::collapse() we can easy to merge multidimensional array or multiple array in single array.
Here below an example, Follow the example and apply in your laravel application.
<?php
use Illuminate\Support\Facades\Route;
use Arr;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/arr-add', function () {
// Example 1
$array = Arr::collapse([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
// Output => [1, 2, 3, 4, 5, 6, 7, 8, 9]
});
I hope that this example will help you to merge multidimensional array convert into single array.
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- How to Integrate Razorpay Payment Gateway in Laravel 9 Example
- Route Resource Controller Laravel
- Get message-id mail send mailable laravel
- Convert base64 String To Image And Upload In Laravel
- How To Generate A Sitemap In Laravel 6/7/8/9
- Cashfree Payment Gateway Integration In Laravel
- How to Generate PDF File Using DomPDF In Laravel 9 Example
- could not find driver (SQL: select count(*) as aggregate from "users" where "email" = admin@gmail.com)
- How To Change The Views Or Blade File Path In Laravel
- Laravel 9 Authorize.Net Payment Gateway Integration