Converting multi-dimensional array into row data Input:
$input = [
    'category' =&gt; [
        '1' =&gt; [
            'name' =&gt; 'c1',
            'attribute' =&gt; [
                '1' =&gt; [
                    'name' =&gt; 'a1',
                    'option' =&gt; [
                        '1' =&gt; [
                            'name' =&gt; 'o1'
                        ],
                        '2' =&gt; [
                            'name' =&gt; 'o2'
                        ]
                    ]
                ],
                '2' =&gt; [
                    'name' =&gt; 'a2',
                    'option' =&gt; [
                        '3' =&gt; [
                            'name' =&gt; 'o3'
                        ],
                        '4' =&gt; [
                            'name' =&gt; 'o4'
                        ]
                    ]
                ]
            ]
        ],
        '2' =&gt; [
            'name' =&gt; 'c2',
            'attribute' =&gt; [
                '3' =&gt; [
                    'name' =&gt; 'a3',
                    'option' =&gt; [
                        '5' =&gt; [
                            'name' =&gt; 'o5'
                        ],
                        '6' =&gt; [
                            'name' =&gt; 'o6'
                        ]
                    ]
                ],
                '4' =&gt; [
                    'name' =&gt; 'a4',
                    'option' =&gt; [
                        '7' =&gt; [
                            'name' =&gt; 'o7'
                        ],
                        '8' =&gt; [
                            'name' =&gt; 'o8'
                        ]
                    ]
                ]
            ]
        ]
    ]
];

Output:
$data = [
    ['category' =&gt; 1, 'categoryname' =&gt; 'c1', 'attribute' =&gt; 1, 'attributename' =&gt; 'a1', 'option' =&gt; 1, 'optionname' =&gt; 'o1'],
    ['category' =&gt; 1, 'categoryname' =&gt; 'c1', 'attribute' =&gt; 1, 'attributename' =&gt; 'a1', 'option' =&gt; 2, 'optionname' =&gt; 'o2'],
    ['category' =&gt; 1, 'categoryname' =&gt; 'c1', 'attribute' =&gt; 2, 'attributename' =&gt; 'a2', 'option' =&gt; 3, 'optionname' =&gt; 'o3'],
    ['category' =&gt; 1, 'categoryname' =&gt; 'c1', 'attribute' =&gt; 2, 'attributename' =&gt; 'a2', 'option' =&gt; 4, 'optionname' =&gt; 'o4'],
    ['category' =&gt; 2, 'categoryname' =&gt; 'c2', 'attribute' =&gt; 3, 'attributename' =&gt; 'a3', 'option' =&gt; 5, 'optionname' =&gt; 'o5'],
    ['category' =&gt; 2, 'categoryname' =&gt; 'c2', 'attribute' =&gt; 3, 'attributename' =&gt; 'a3', 'option' =&gt; 6, 'optionname' =&gt; 'o6'],
    ['category' =&gt; 2, 'categoryname' =&gt; 'c2', 'attribute' =&gt; 4, 'attributename' =&gt; 'a4', 'option' =&gt; 7, 'optionname' =&gt; 'o7'],
    ['category' =&gt; 2, 'categoryname' =&gt; 'c2', 'attribute' =&gt; 4, 'attributename' =&gt; 'a4', 'option' =&gt; 8, 'optionname' =&gt; 'o8'],
];

Method I used:
$final = [];

    foreach ($input as $k =&gt; $d) {
        foreach ($d as $ki =&gt; $i) {
            foreach ($i['attribute'] as $ka =&gt; $a) {
                foreach ($a['option'] as $ko =&gt; $o) {
                    array_push($final, ['category' =&gt; $ki, 'categoryname' =&gt; $i['name'], 'attribute' =&gt; $ka, 'attributename' =&gt; $a['name'], 'option' =&gt; $ko, 'optionname' =&gt; $o['name']]);
                };
            }
        }
    };

I want to convert the $input(INPUT) data into $data(OUTPUT). I mentioned my method which I used. Is it the best way we can use or is there any better option in terms of faster execution? What would be a better approach, or is it possible to just convert it into a one-liner?
As long as this input array is static in its depth and structure, the best and fastest technique (due to lowest overhead) is to use old-school loops.
Beyond that, I would:

Not declare variable that will not be used
Use square brace pushing syntax
Avoid excessively wide lines of code which demand the developer to horizontally scroll
Use words as variable names to make your code more readable

Code: (Demo)
$final = [];
foreach ($categorizedOptions as $categories) {
    foreach ($categories as $categoryId =&gt; $category) {
        foreach ($category['attribute'] as $attributeId =&gt; $attribute) {
            foreach ($attribute['option'] as $optionId =&gt; $option) {
                $final[] = [
                    'category' =&gt; $categoryId,
                    'categoryname' =&gt; $category['name'],
                    'attribute' =&gt; $attributeId,
                    'attributename' =&gt; $attribute['name'],
                    'option' =&gt; $optionId,
                    'optionname' =&gt; $option['name']
                ];
            }
        }
    }
}

Don't worry with trying to convert this code into some sexy one-liner.  Trying to do so with recursion or nested functions will make your code ugly and negatively impact performance.
Even trying to get fancy with &quot;array destructuring&quot; and a compact() call don't look worth the effort.  (Demo)