How to use flatten() helper function to convert a multi-dimensional array into a single array in Laravel

Hello, In this tutorial, I would to show you, how can you convert a multi-dimensional array into a single array. Sometimes, we fetch some problems when we fetch multi-relational data. We can use flatter() helper, to easily convert a more readable array. Let's me how to do that,

Example: 

use Illuminate\Support\Arr;

        $array = [
        'name' => 'english',
        'languages' =>
            'programming'=> [
                'php',
                'java',
                'c++',
                'c#',
            ],
        ];

        $flattened = Arr::flatten($array);

Output:

=> [
     "english",
    "php",
    "java",
    "c",
    "c++",
  ]

 

Hope, it will help you.

Related Post

How to Get Current Route Name in Laravel
How to get All Column Name from a table using Laravel
How to Use Query Scope in Laravel Eloquent
How to Add Country List in Laravel App?