I have this array of VARIATIONS here, which contains 5 items, with their own IDs. Each item has 2 attributes, the size (Large or Small) and the color (red blue or green). I want an array that is structured like this:
$array[size]=array("Large" => array("color" => array("Blue"=340,"Green"=341,"Red"=342)))
$array[size]=array("Small" => array("color" => array("Blue"=343,"Red"=345)))
The above code is not actual code nor does it seem like the correct syntax for an array, i just wanted to show how i would like the array to be arranged by looping through the original array.
I don't know how else to demonstrate it or explain it but i want a multidimensional array that has the FIRST attribute as the first KEY (size in this case) which has an array of the option (Large for example) which has an array of the SECOND attribute (color in this case) and in that to have an array of all the possible colors for that size, with their corresponding IDs.
Here is the full original array output that i want to manipulate and turn it into the structure described above. I've tried all kinds of array methods and functions but couldn't get the logic to work.
[variations] => Array
(
[0] => Array
(
[id] => 340
[attributes] => Array
(
[0] => Array
(
[name] => size
[option] => Large
)
[1] => Array
(
[name] => color
[option] => Blue
)
)
)
[1] => Array
(
[id] => 341
[attributes] => Array
(
[0] => Array
(
[name] => size
[option] => Large
)
[1] => Array
(
[name] => color
[option] => Green
)
)
)
[2] => Array
(
[id] => 342
[attributes] => Array
(
[0] => Array
(
[name] => size
[option] => Large
)
[1] => Array
(
[name] => color
[option] => Red
)
)
)
[3] => Array
(
[id] => 343
[attributes] => Array
(
[0] => Array
(
[name] => size
[option] => Small
)
[1] => Array
(
[name] => color
[option] => Blue
)
)
)
[4] => Array
(
[id] => 345
[attributes] => Array
(
[0] => Array
(
[name] => size
[option] => Small
)
[1] => Array
(
[name] => color
[option] => Red
)
)
)
)