I have the following function and it's objective is to filter in the array tree those elements what are not conform to the search index and eliminate theme. I can get this function to bring the desired results.
public function negativeKeywordsFilter($products, $negative_keywords){
$nk=explode(',',$negative_keywords);
foreach ($products['productItems'] as $product){
foreach ($product as $item){
foreach ($nk as $word){
if (stripos($item['name'],$word) !== false){
unset($item);
}
}
}
}
return $products;
}
My array looks as follows:
array(
'page' => '1',
'items' => '234',
'items' => array(
'item' => array(
0 => array(
'name' => 'second',
'description' => 'some description'
)
)
)
)
)
If name is matching with the descriptions, then the value should be unset.
the problem is you only unset a variable which has a copy of the value, you need to unset the corresponding element in the array.