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
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Input file with max size validation in laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Automatically remove records using Prunable trait in Laravel
- Datetime field in Laravel migration
- Route [password.request] not defined
- How to get laravel errors folder in views directory in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Convert input array to comma-separated string in laravel controller
- How to fill a column automatically while creating records in Laravel
- How to avoid duplicate entries in pivot table in Laravel
- Attempt to read property "avatar" on null in Laravel
- Php artisan make model, factory, migration and controller in single command
- After image selected get validation error in laravel
- How to Access Array in blade laravel
- Call to a member function pluck() on null
- How to check query string exists or not in laravel blade
- How to customize or Change validation error messages
- How to increment column value of table in Laravel
- Display first n record from collection in laravel view
- The POST method is not supported for this route. Supported methods: PUT.
- How to add dynamic page title in Laravel view
- Laravel append URI in route
- Validation errors for multiple forms on same page Laravel
- Link storage folder in laravel 8