Hello! There is an array that comes in view:
Array ( [0] => Array ( [name] => product_1 [model] => model_1 [option] => Array ( [0] => Array ( [product_id] => 47 [name] => Размер [value] => 39 ) ) [quantity] => 10 ) [1] => Array ( [name] => product_1 [model] => model_1 [option] => Array ( [0] => Array ( [product_id] => 47 [name] => Размер [value] => 40 ) ) [quantity] => 20 ) [2] => Array ( [name] => product_2 [model] => model_2 [option] => Array ( [0] => Array ( [product_id] => 55 [name] => Размер [value] => 44 ) ) [quantity] => 30 ) ) и т.д. It is necessary to remove duplicates and re-record so that it looks like this:
Array ( [0] => Array ( [name] => product_1 [model] => model_1 [option] => Array ( [0] => Array ( [product_id] => 47 [name] => Размер [value] => 39 ) [1] => Array ( [product_id] => 47 [name] => Размер [value] => 40 ) ) [quantity] => 10 ), [1] => Array ( [name] => product_2 [model] => model_2 [option] => Array ( [0] => Array ( [product_id] => 55 [name] => Размер [value] => 44 ) ) [quantity] => 30 ) Model can not be touched. Now I do this:
$keys=array(); // Массив ключей, которые уже встречались foreach($products as $k=>$val) { if(array_key_exists($val['model'],$keys)) { unset($products[$k]); } else { $keys[$val['model']]=1; } } Now removes duplicates, but how to make it so that it adds from duplicate [option] ?
optionsfrom there first and add them to the final element? - teranquantityis taken from the first result? - teran