public function testSubar() { $array = CArray::fromElements("a", "b", "c", "d", "e"); $subarray = CArray::subar($array, 3); $this->assertTrue(CArray::equals($subarray, CArray::fromElements("d", "e"))); $subarray = CArray::subar($array, 1, 3); $this->assertTrue(CArray::equals($subarray, CArray::fromElements("b", "c", "d"))); // Special cases. $subarray = CArray::subar($array, 5); $this->assertTrue($subarray->getSize() == 0); $subarray = CArray::subar($array, 5, 0); $this->assertTrue($subarray->getSize() == 0); $subarray = CArray::subar($array, 0, 0); $this->assertTrue($subarray->getSize() == 0); $subarray = CArray::subar($array, 2, 0); $this->assertTrue($subarray->getSize() == 0); }
/** * Returns a sequence of elements from an array, as another array. * * This method works much like `substr` 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 $length **OPTIONAL. Default is** *as many elements as the starting element is followed by*. The * number of elements in the sequence to be copied. * * @return CArrayObject The array containing the copied elements. */ public function subar($startPos, $length = null) { return self::fromSplArray(CArray::subar($this->m_splArray, $startPos, $length)); }