I am trying to stop an array of items from duplicating everytime the loop goes through. I would think unique array would solve my problem but it doesnt seem to be working. Is there an alternative or am I doing something wrong?
This is the array that i am parsing. For example bag shows up several times. I am trying get it to show up once.
Array
(
[0] => bag
[1] => wallet
[2] => accessori
[3] => sunglass
[4] => clutch
[5] => tote
)
Array
(
[0] => handbag
[1] => faux
[2] => leather
[3] => bag
[4] => clutch
[5] => hobo
[6] => purs
[7] => wallet
[8] => tote
[9] => messeng
)
Array
(
[0] => bag
[1] => book
)
This is my code.
foreach($json as $keywords){
foreach($keywords as $keyword){
print_r(array_unique($keyword['keywords']));
}
}
Thank you in advance.
array_unique()does not work recursively, you will have to implement a wrapper for that and 2. I cannot spot any key named'keywords'in your arrays...