I have the following array
Array
(
[0] => Array
(
[id_product_option] => 1
[id_option] => 1
[id_product] => 3
[option_value] => White
[option_name] => color
)
[1] => Array
(
[id_product_option] => 2
[id_option] => 2
[id_product] => 3
[option_value] => 9oz
[option_name] => size
)
[2] => Array
(
[id_product_option] => 3
[id_option] => 1
[id_product] => 3
[option_value] => Blue
[option_name] => color
)
)
What i need to do is loop through it and find the ones where the id_option values match and group them into a new array that should look like
Array
(
[0] => Array
[0] => Array
(
[id_product_option] => 1
[id_option] => 1
[id_product] => 3
[option_value] => White
[additional_cost] => 0
[is_active] => 1
[created_on] => 2014-11-15 01:29:35
[option_name] => color
[option_text] => Color
)
[1] => Array
(
[id_product_option] => 3
[id_option] => 1
[id_product] => 3
[option_value] => Blue
[additional_cost] => 0
[is_active] => 1
[created_on] => 2014-11-15 01:29:35
[option_name] => color
[option_text] => Color
)
[1] => Array
(
[id_product_option] => 2
[id_option] => 2
[id_product] => 3
[option_value] => 9oz
[additional_cost] => 0
[is_active] => 1
[created_on] => 2014-11-15 01:29:35
[option_name] => size
[option_text] => Size
)
)
where the options with id_option 1 are grouped together
I tried the following but no luck
$groupOptions = array();
$prev = "";
foreach($productOptions as $key=>$options) {
$id_option = $options['id_option'];
if($id_option != $prev) {
$groupOptions[] = $productOptions[$key];
}
$prev = $id_option;
}