/** * @en Erase specified items inside array * @ru Убирает полные копии указанных элементов из массива * * $haystack = array('a', 'b', 'f', 'r', 'b', 'v', 'r', 'b', 't', 'a'); * $needle = array('a', 'b'); * * $result = array_erase($needle, $haystack); # array('f', 'r', 'v', 'r', 'b', 't'); * * @param array $needle * @param array $haystack * @param int $count * * @return mixed */ public static function erase($needle, $haystack, $count = null) { if ($count === null) { $count = items::count($needle, $haystack); } if (!$count) { return $haystack; } $result = $haystack; foreach ($needle as $item) { $index = array_keys($result, $item); for ($i = 0; $i < $count; $i++) { unset($result[$index[$i]]); } } return $result; }