예제 #1
0
 public function testSymmetricDifference()
 {
     // Using the default comparator.
     $array0 = CArray::fromElements("a", "b", "c", "d", "e", "f");
     $array1 = CArray::fromElements("g", "b", "h", "d", "i", "f");
     $array = CArray::symmetricDifference($array0, $array1);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "c", "e", "g", "h", "i")));
     // Using a custom comparator.
     $array0 = CArray::fromElements("a", "b", "c", "d", "e", "f");
     $array1 = CArray::fromElements("G", "B", "H", "D", "I", "F");
     $comparator = function ($string0, $string1) {
         return CString::toLowerCase($string0) === CString::toLowerCase($string1);
     };
     $array = CArray::symmetricDifference($array0, $array1, $comparator);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "c", "e", "G", "H", "I")));
 }
예제 #2
0
 /**
  * From two arrays, returns only those elements that are present in one of the arrays but not in the other, as a
  * new array.
  *
  * None of the source arrays is modified by this method.
  *
  * You can use your own comparator for the comparison of the elements in the arrays, but the default comparator has
  * got you covered when comparing 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  array $fromArray The second array.
  * @param  callable $comparator **OPTIONAL. Default is** `CComparator::EQUALITY`. The function or method to be
  * used for the comparison of any two elements. If this parameter is provided, the comparator should take two
  * parameters, with the first parameter being an element from *this* array and the second parameter being an
  * element from the second array, and return `true` if the two elements are equal and `false` otherwise.
  *
  * @return CArrayObject The symmetric difference array between the two arrays.
  *
  * @link   CComparator.html CComparator
  */
 public function symmetricDifference($fromArray, $comparator = CComparator::EQUALITY)
 {
     return self::fromSplArray(CArray::symmetricDifference($this->m_splArray, $fromArray, $comparator));
 }