<?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 $category => ['name' => $categoryname, 'attribute' => $attributes]) {
foreach ($attributes as $attribute => ['name' => $attributename, 'option' => $options]) {
foreach ($options as $option => ['name' => $optionname]) {
$final[] = compact(['category', 'categoryname', 'attribute', 'attributename', 'option', 'optionname']);
}
}
}
}
var_export($final);
preferences:
27.79 ms | 405 KiB | 5 Q