예제 #1
0
 public function testSplice()
 {
     $array = CArray::fromElements("a", "b", "c", "d", "e");
     $remArray = CArray::splice($array, 3);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c")));
     $this->assertTrue(CArray::equals($remArray, CArray::fromElements("d", "e")));
     $array = CArray::fromElements("a", "b", "c", "d", "e");
     $remArray = CArray::splice($array, 1, 3);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "e")));
     $this->assertTrue(CArray::equals($remArray, CArray::fromElements("b", "c", "d")));
     // Special cases.
     $array = CArray::fromElements("a", "b", "c");
     $remArray = CArray::splice($array, 3);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c")));
     $this->assertTrue(CArray::equals($remArray, CArray::make()));
     $array = CArray::fromElements("a", "b", "c");
     $remArray = CArray::splice($array, 3, 0);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c")));
     $this->assertTrue(CArray::equals($remArray, CArray::make()));
     $array = CArray::fromElements("a", "b", "c");
     $remArray = CArray::splice($array, 0, 0);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c")));
     $this->assertTrue(CArray::equals($remArray, CArray::make()));
     $array = CArray::fromElements("a", "b", "c");
     $remArray = CArray::splice($array, 1, 0);
     $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c")));
     $this->assertTrue(CArray::equals($remArray, CArray::make()));
 }
예제 #2
0
 /**
  * Removes a sequence of elements from an array and returns the removed elements, as another array.
  *
  * Use `removeSubarray` method if you don't care about what happens to the elements after they are removed.
  *
  * The method allows for the targeted sequence to be empty.
  *
  * @param  int $startPos The position of the first element in the sequence to be removed.
  * @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 removed.
  *
  * @return CArrayObject The array containing the removed elements.
  *
  * @link   #method_removeSubarray removeSubarray
  */
 public function splice($startPos, $length = null)
 {
     return self::fromSplArray(CArray::splice($this->m_splArray, $startPos, $length));
 }