
Convert multidimensional array to single array in Laravel
Convert multidimensional array to single array in Laravel
Through the use of the programming language, we will work together to solve the "Convert multidimensional array to single array in Laravel" puzzle in this lesson.
You can convert multidimensional array to single array in Laravel.-
Convert multidimensional array into single array
//routes\web.php use App\Http\Controllers\HomeController; Route::get('/convert-array',[HomeController::class, 'multidimensionalToSingleArray']); //app\Http\Controllers\HomeController.php public function multidimensionalToSingleArray(){ $myarray = array( array("Ankit", "Ram", "Shyam"), array("Unnao", "Trichy", "Kanpur") ); $arrayData = $this->array_flatten($myarray); print_r($arrayData); } private function array_flatten($array) { if (!is_array($array)) { return FALSE; } $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result = array_merge($result, $this->array_flatten($value)); } else { $result[$key] = $value; } } return $result; }
Output :
Array ( [0] => Ankit [1] => Ram [2] => Shyam [3] => Unnao [4] => Trichy [5] => Kanpur )
Input dataarray(
array("Ankit", "Ram", "Shyam"),
array("Unnao", "Trichy", "Kanpur")
);
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Page loader in laravel
- How to upload multiple images after preview in laravel using cropper js
- Laravel hasmany select not working
- How to increment column value of table in Laravel
- Calculate age from date of birth in Laravel
- Laravel create table migration with model
- How to check column value of a record is null or not in laravel
- Post model with title and body in laravel 8
- Laravel 9 pagination with search filter
- Laravel URL validation not working
- 419 page expired error in Laravel
- Get duplicate records in laravel
- Get content from web URL in laravel
- How to get column names from table in Laravel
- How to use more than one query scope in Laravel
- Get current month records in laravel 7/8
- Order by multiple columns in Laravel
- Laravel upload file with original file name
- Laravel specific table Migration
- Extract only time from datetime in laravel
- Recursive function example code PHP Laravel
- How to display HTML tags In Laravel blade
- Insert Comma Separated Values in laravel
- How to disable timestamps in laravel
- How to insert ckeditor data into database in Laravel?