PhpOffice\PhpPresentation\HashTable::remove PHP Method

remove() public method

Remove HashTable item
public remove ( ComparableInterface $pSource )
$pSource ComparableInterface Item to remove
    public function remove(ComparableInterface $pSource)
    {
        if (isset($this->items[$pSource->getHashCode()])) {
            unset($this->items[$pSource->getHashCode()]);
            $deleteKey = -1;
            foreach ($this->keyMap as $key => $value) {
                if ($deleteKey >= 0) {
                    $this->keyMap[$key - 1] = $value;
                }
                if ($value == $pSource->getHashCode()) {
                    $deleteKey = $key;
                }
            }
            unset($this->keyMap[count($this->keyMap) - 1]);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  */
 public function testRemove()
 {
     $object = new HashTable();
     $oSlide1 = new Slide();
     $oSlide2 = new Slide();
     $oSlide3 = new Slide();
     // Add Object
     $this->assertNull($object->add($oSlide1));
     $this->assertNull($object->add($oSlide2));
     $this->assertNull($object->add($oSlide3));
     // Remove
     $this->assertNull($object->remove($oSlide2));
     $this->assertCount(2, $object->toArray());
     $this->assertNull($object->remove($oSlide3));
     $this->assertCount(1, $object->toArray());
 }