Ejemplo n.º 1
0
 public function testSlice()
 {
     $array = CArray::fromElements("a", "b", "c", "d", "e");
     $subarray = CArray::slice($array, 1, 4);
     $this->assertTrue(CArray::equals($subarray, CArray::fromElements("b", "c", "d")));
     $subarray = CArray::slice($array, 3, 5);
     $this->assertTrue(CArray::equals($subarray, CArray::fromElements("d", "e")));
     // Special cases.
     $subarray = CArray::slice($array, 5, 5);
     $this->assertTrue($subarray->getSize() == 0);
     $subarray = CArray::slice($array, 0, 0);
     $this->assertTrue($subarray->getSize() == 0);
     $subarray = CArray::slice($array, 2, 2);
     $this->assertTrue($subarray->getSize() == 0);
 }
Ejemplo n.º 2
0
 /**
  * An alias for the previous method.
  *
  * Returns a sequence of elements from an array, as another array, with both starting and ending positions
  * specified.
  *
  * This method works much like `substring` method of the CUStringObject class.
  *
  * The method allows for an empty array to be returned.
  *
  * @param  int $startPos The position of the first element in the sequence to be copied.
  * @param  int $endPos The position of the element that *follows* the last element in the sequence to be copied.
  *
  * @return CArrayObject The array containing the copied elements.
  */
 public function slice($startPos, $endPos)
 {
     return self::fromSplArray(CArray::slice($this->m_splArray, $startPos, $endPos));
 }