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!
$productsbeing generated by an sql resultset? If so, please post that query.$data ['products']doesn't need to be in your question -- you don't use it. Please post the full data that is in$products. I have a sneaking suspicion that you have received fast/poor answers (in a hurry to earn rep points) that have not considered what is best for you, your project, and future SO readers. After posting this critical information, you may discover a more professional method to employ.