Hope someone can help me out here.
Imagine the following array:
Array
(
[blue__##__m__##__10] => 13
[blue__##__m__##__20] => 13
[blue__##__m__##__30] => 13
[blue__##__xl__##__10] => 18
[blue__##__xl__##__20] => 18
[blue__##__xl__##__30] => 18
[blue__##__xs__##__10] => 12
[blue__##__xs__##__20] => 12
[blue__##__xs__##__30] => 12
[green__##__m__##__10] => 17
[green__##__m__##__20] => 17
[green__##__m__##__30] => 17
[green__##__xl__##__10] => 15
[green__##__xl__##__20] => 15
[green__##__xl__##__30] => 15
[green__##__xs__##__10] => 11
[green__##__xs__##__20] => 11
[green__##__xs__##__30] => 11
[red__##__m__##__10] => 16
[red__##__m__##__20] => 16
[red__##__m__##__30] => 16
[red__##__xl__##__10] => 10
[red__##__xl__##__20] => 10
[red__##__xl__##__30] => 10
[red__##__xs__##__10] => 21
[red__##__xs__##__20] => 21
[red__##__xs__##__30] => 21
)
I want to organize it on the most common attribute (the ## is from a implode* the rest is attributes) removing the less uncommon.
The result should be:
Array
(
[blue] => array[13,18,12]
[green] => array[17,15,11]
[red] => array[16,10,21]
)
Maybe I have to ask user to provide excluded attributes for it to work? Ex: Exclude [xs,xl,xs,10,20,30] or by the attribute group [attribute_pa_size,attribute_height] (see original implode)
*Original array before implode:
Array
(
[0] => Array
(
[pid] => 100
[variations] => Array
(
[0] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => m
[attribute_height] => 10
)
[image_id] => 13
)
[1] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => m
[attribute_height] => 20
)
[image_id] => 13
)
[2] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => m
[attribute_height] => 30
)
[image_id] => 13
)
[3] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xl
[attribute_height] => 10
)
[image_id] => 18
)
[4] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xl
[attribute_height] => 20
)
[image_id] => 18
)
[5] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xl
[attribute_height] => 30
)
[image_id] => 18
)
[6] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xs
[attribute_height] => 10
)
[image_id] => 12
)
[7] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xs
[attribute_height] => 20
)
[image_id] => 12
)
[8] => Array
(
[attributes] => Array
(
[attribute_pa_color] => blue
[attribute_pa_size] => xs
[attribute_height] => 30
)
[image_id] => 12
)
[9] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => m
[attribute_height] => 10
)
[image_id] => 17
)
[10] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => m
[attribute_height] => 20
)
[image_id] => 17
)
[11] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => m
[attribute_height] => 30
)
[image_id] => 17
)
[12] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xl
[attribute_height] => 10
)
[image_id] => 15
)
[13] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xl
[attribute_height] => 20
)
[image_id] => 15
)
[14] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xl
[attribute_height] => 30
)
[image_id] => 15
)
[15] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xs
[attribute_height] => 10
)
[image_id] => 11
)
[16] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xs
[attribute_height] => 20
)
[image_id] => 11
)
[17] => Array
(
[attributes] => Array
(
[attribute_pa_color] => green
[attribute_pa_size] => xs
[attribute_height] => 30
)
[image_id] => 11
)
[18] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => m
[attribute_height] => 10
)
[image_id] => 16
)
[19] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => m
[attribute_height] => 20
)
[image_id] => 16
)
[20] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => m
[attribute_height] => 30
)
[image_id] => 16
)
[21] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xl
[attribute_height] => 10
)
[image_id] => 10
)
[22] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xl
[attribute_height] => 20
)
[image_id] => 10
)
[23] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xl
[attribute_height] => 30
)
[image_id] => 10
)
[24] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xs
[attribute_height] => 10
)
[image_id] => 21
)
[25] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xs
[attribute_height] => 20
)
[image_id] => 21
)
[26] => Array
(
[attributes] => Array
(
[attribute_pa_color] => red
[attribute_pa_size] => xs
[attribute_height] => 30
)
[image_id] => 21
)
)
)
)
Thanks