public function testInsert() { $array = CArray::fromElements("a", "b", "c", "d", "e"); CArray::insert($array, 3, "x"); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "x", "d", "e"))); $array = CArray::fromElements("a", "b", "c", "d", "e"); CArray::insert($array, 0, "x"); $this->assertTrue(CArray::equals($array, CArray::fromElements("x", "a", "b", "c", "d", "e"))); // Special cases. $array = CArray::fromElements("a", "b", "c", "d", "e"); CArray::insert($array, 5, "x"); $this->assertTrue(CArray::equals($array, CArray::fromElements("a", "b", "c", "d", "e", "x"))); $array = CArray::make(); CArray::insert($array, 0, "x"); $this->assertTrue(CArray::equals($array, CArray::fromElements("x"))); }
/** * Inserts an element into an array. * * As a special case, the position of insertion can be equal to the array's length, which would make this method * work like `push` method. * * @param int $atPos The position at which the new element is to be inserted. * @param mixed $insertElement The new element. * * @return void */ public function insert($atPos, $insertElement) { CArray::insert($this->m_splArray, $atPos, $insertElement); }