Skip to content
Advertisement

Array push and merge in php

How to merge one array with multple elements but the same index into on array with all index in PHP. I have one array look like this and i want to merge into one array.

JavaScript

and my expected result i want like this

JavaScript

Anyone can help in PHP please.

Advertisement

Answer

Since you want to change a multi-dimensional array to single dimension. Laravel has a beautiful collection method as flatten(). This flattens your multi dimensional array to single array. In your case you can use:

JavaScript

to get the desired result.

Know more about it: https://laravel.com/docs/8.x/collections#method-flatten

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement