3v4l.org

run code in 300+ PHP versions simultaneously
<?php $categorizedOptions = [ 'category' => [ '1' => [ 'name' => 'c1', 'attribute' => [ '1' => [ 'name' => 'a1', 'option' => [ '1' => [ 'name' => 'o1' ], '2' => [ 'name' => 'o2' ] ] ], '2' => [ 'name' => 'a2', 'option' => [ '3' => [ 'name' => 'o3' ], '4' => [ 'name' => 'o4' ] ] ] ] ], '2' => [ 'name' => 'c2', 'attribute' => [ '3' => [ 'name' => 'a3', 'option' => [ '5' => [ 'name' => 'o5' ], '6' => [ 'name' => 'o6' ] ] ], '4' => [ 'name' => 'a4', 'option' => [ '7' => [ 'name' => 'o7' ], '8' => [ 'name' => 'o8' ] ] ] ] ] ] ]; $final = []; foreach ($categorizedOptions as $categories) { foreach ($categories as $categoryId => $category) { foreach ($category['attribute'] as $attributeId => $attribute) { foreach ($attribute['option'] as $optionId => $option) { $final[] = [ 'category' => $categoryId, 'categoryname' => $category['name'], 'attribute' => $attributeId, 'attributename' => $attribute['name'], 'option' => $optionId, 'optionname' => $option['name'] ]; } } } } var_export($final);

preferences:
23.09 ms | 404 KiB | 5 Q