I know this is a very common and repeated subject, but after spending some hours of googling I didn't find the right solution for my problem.
Using a foreach
loop I'm filling an array, each row including a key and value. I just want to prevent duplicates
or remove them.
$data['products'] = array();
$data['stores'] = array();
foreach ($products as $product) {
//if (!in_array($product['store_id'], $data['stores'])) {
if (!array_key_exists($product['store_id'], $data['stores'])) {
$data['stores'][] = array(
'store_id' => $product['store_id'],
'store_name' => $product['store_name']
);
}
}
The result of print_r($data['stores'])
:
Array
(
[0] => Array
(
[store_id] => 1
[store_name] => Karaca
)
[1] => Array
(
[store_id] => 1
[store_name] => Karaca
)
[2] => Array
(
[store_id] => 7
[store_name] => nurteks
)
[3] => Array
(
[store_id] => 7
[store_name] => nurteks
)
)
I tried all suggestions, but I don't know how to figure it out.
Thanks for any kind help!