Removes the last item in the list and returns it. This is the same as takeAt(size() - 1).
This function assumes the list is not empty. To avoid failure, call isEmpty() before
calling this function.

@return mixed|null
964731
public function takeLast()
    {
        if (count($this->list) <= 0) {
            return null;
        }

        $value = $this->last();

        unset($this->list[$this->count() - 1]);

        return $value;
    }
1234344
public function pop()
    {
        if (null !== $this->getDraft()) {
            return $this->getDraft()->pop();
        }

        $last = $this->last();

        if (null === $last) {
            return;
        }

        array_pop($this->_data);
        $content = null;
        if (isset($this->subcontentmap[$last->getUid()])) {
            $content = $this->_subcontent->get($this->subcontentmap[$last->getUid()]);
            $this->_subcontent->removeElement($content);
            unset($this->subcontentmap[$last->getUid()]);
        }

        $this->rewind();

        return $content;
    }
1044043
public function pop()
    {
        $this->throwExceptionIfEmpty();

        $arrayCopy = $this->getArrayCopy();
        $lastElement = array_pop($arrayCopy);
        $this->exchangeArray($arrayCopy);
        return $lastElement;
    }
264668
protected function NextItem()
	{
		if ( $this->empty ) return null;

		/**
		 * @var int $index
		 */
		$index = $this->getCurrentPosition() + 1;
		if ( $index < count( $this->buffer ) )
		{
			return $this->buffer[ $index ];
		}
		else if ( ! $this->filled )
		{
			if ( ! $this->src->getIsFinished() )
			{
				if ( $this->src->MoveNext() )
				{
					$current = $this->src->getCurrent();
					$this->buffer[] = $current;
					return $current;
				}
				else
				{
					$this->filled = true;
				}
			}

			if ( ! count( $this->buffer ) )
			{
				$this->empty = true;
			}
		}

		return null;
	}
1206341
public function last()
    {
        $keys = AccessHelper::collectionKeys($this->data);

        if (empty($keys)) {
            return null;
        }

        $value = $this->data[end($keys)] ? $this->data[end($keys)] : null;

        return AccessHelper::isCollectionType($value) ? new static($value, $this->options) : $value;
    }
1168855
public function clear()
    {
        $this->emitOnChange(__METHOD__);
        $items = &$this->items();
        if (count($this->listeners('item.remove'))) {
            foreach ($items as $item) {
                $this->emit('item.remove', [$item, $this]);
            }
        }

        // It's not mistake that $items never used after assigning empty array.
        // Yep, it really clears the collection.
        $items = [];
        $this->endEmitOnChange(__METHOD__);
        return $this;
    }
1025304
public function pop()
    {
        if ($this->count() == 0) {
            return null;
        }
        $ret = $this->getLast();
        $lastKey = $this->getInternalIterator()->key();
        $this->offsetUnset((string) $lastKey);

        return $ret;
    }
683375
public function last()
    {
        if ($this->isEmpty()) {
            return $this->makeItem(null);
        }

        $arResultIDList = $this->arElementIDList;

        $iElementID = array_pop($arResultIDList);

        return $this->makeItem($iElementID);
    }
1192641
public function getCurrentPageLastItem()
    {
        $first = $this->getCurrentPageFirstItem();

        if (empty($first)) {
            return 0;
        }

        $last = $first + $this->limit - 1;

        if ($last > $this->total) {
            return $this->total;
        }

        return $last;
    }
739481
public function remove()
    {
        $key = $this->request->param('ID');
        $title = "";

        if (!empty($key)) {
            foreach ($this->items as $item) {
                if ($item->Key == $key) {
                    $title = $item->Title;
                    $this->items->remove($item);
                }
            }

            $this->save();
            
            if ($title) {
                $this->setSessionMessage(
                    "bad",
                    _t(
                        "Checkout.RemovedItem",
                        "Removed '{title}' from your cart",
                        "Message to tell user they removed an item",
                        array("title" => $title)
                    )
                );
            }
        }

        return $this->redirectBack();
    }
713175
protected function getLastValidItem()
    {
        $validItems = $this->getValidItems();
        $result = null;
        if( !empty( $validItems ) )
        {
            $result = null;
            $lastTime = 0;
            foreach($validItems as $item)
            {
                if( $item -> attribute( 'ts_visible' ) >= $lastTime)
                {
                    $lastTime = $item -> attribute( 'ts_visible' );
                    $result = $item;
                }
            }
        }
        return $result;
    }
375981
public function remove()
    {
        $args = func_get_args();
        
        if (count($args) == 0) {
            return $this;
        }
        
        $last = array_pop($args);
        
        $pointer = &$this->data;
        foreach ($args as $i => $step) {
            if (!isset($pointer[$step])
                || !is_array($pointer[$step])
            ) {
                return $this;
            }

            $pointer = &$pointer[$step];
        }
        
        unset($pointer[$last]);
        
        return $this;
    }
438810
public function first()
    {
        $this->sort();

        return !empty($this->items) ? reset($this->items) : null;
    }
599099
public function remove()
    {
        $key = $this->request->param('ID');
        $item = null;
        $title = null;

        if (isset($key)) {
            $item = $this
                ->Items()
                ->find("Key", $key);
        }

        if (isset($item)) {
            $title = $item->Title;
            ShoppingCartFactory::create()->removeItem($item);

            $form = $this->CartForm();
            $form->sessionMessage(_t(
                "ShoppingCart.RemovedItem",
                "Removed '{title}' from your cart",
                ["title" => $title]
            ));
        }

        return $this->redirectBack();
    }
247539
public function tail()
    {
        $last = count($this->parts) - 1;
        if ($last < 0) {
            return null;
        }

        return $this->parts[$last];
    }
419136
public function pop() {
        $e = array_pop($this->elements);
        $this->fire(new ListDeleteEvent($e, $this->count()));
        return $e;
    }
1045056
public function removeEmpty(): Utility
    {
        $filteredBag = array_filter($this->bag, function ($value) {
            return !empty($value);
        });

        if (!$this->isAssociative()) {
            $filteredBag = array_values($filteredBag);
        }

        return new static($filteredBag);
    }