protected function removeHeader($headerName) { $headerName = CString::trim($headerName); CArray::removeByValue($this->m_requestHeaders, $headerName, function ($element0, $element1) { return CRegex::find($element0, "/^\\h*" . CRegex::enterTd($element1) . "\\h*:/i"); }); }
public function testRemoveByValue() { // Using the default comparator. $array = CArray::fromElements("a", "b", "c", "d", "e"); $anyRemoval = CArray::removeByValue($array, "d"); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "e"))); $this->assertTrue($anyRemoval); $array = CArray::fromElements("a", "b", "c", "d", "e", "c", "d", "e", "c", "d", "e"); $anyRemoval = CArray::removeByValue($array, "d"); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "e", "c", "e", "c", "e"))); $this->assertTrue($anyRemoval); $array = CArray::fromElements("a", "b", "c"); $anyRemoval = CArray::removeByValue($array, "d"); $this->assertFalse($anyRemoval); // Using a custom comparator. $comparator = function ($string0, $string1) { return CString::toLowerCase($string0) === CString::toLowerCase($string1); }; $array = CArray::fromElements("a", "b", "c", "d", "e"); $anyRemoval = CArray::removeByValue($array, "D", $comparator); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "e"))); $this->assertTrue($anyRemoval); }
/** * From an array, removes all elements that have a specified value. * * You can use your own comparator for the search, but the default comparator has got you covered when searching * for scalar values, such as `string`, `int`, `float`, and `bool`. And the default comparator is smart enough to * know how to compare objects of those classes that conform to the IEquality or IEqualityAndOrder interface * (static or not), including CUStringObject, CArrayObject, CMapObject, CTime etc. See the * [CComparator](CComparator.html) class for more on this. * * @param mixed $elementValue The value that is common to the elements to be removed. * @param callable $comparator **OPTIONAL. Default is** `CComparator::EQUALITY`. The function or method to be * used for the comparison of element values while searching. If this parameter is provided, the comparator should * take two parameters, with the first parameter being an element from the array and the second parameter being the * searched element, and return `true` if the two elements are equal and `false` otherwise. * * @return bool `true` if any elements were removed, `false` otherwise. * * @link CComparator.html CComparator */ public function removeByValue($elementValue, $comparator = CComparator::EQUALITY) { return CArray::removeByValue($this->m_splArray, $elementValue, $comparator); }