[Solved] remove subarray with php

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. public function negativeKeywordsFilter($products, $negative_keywords){ $nk=explode(‘,’,$negative_keywords); foreach ($products[‘productItems’] as $key1 => $product){ foreach ($product as $key2 => $item){ foreach ($nk as $word){ if (stripos($item[‘name’],$word) !== false){ unset($products[‘productItems’][$key1][$key2]); } } } } … Read more