src/Bag.php
private function iterateReverseFromIndex($fromIndex)
    {
        Assert::nullOrInteger($fromIndex);

        $index = count($this->items);

        if ($index === 0) {
            return;
        }

        if ($fromIndex !== null) {
            $index = $fromIndex < 0 ? max($index + $fromIndex, 1) : min($fromIndex + 1, $index);
        }

        $keys = array_keys($this->items);

        while (--$index >= 0) {
            $key = $keys[$index];
            yield $key => $this->items[$key];
        }
    }
private function iterateReverseFromIndex($fromIndex)
    {
        Assert::nullOrInteger($fromIndex);

        $index = count($this->items);

        if ($index === 0) {
            return;
        }

        if ($fromIndex !== null) {
            $index = $fromIndex < 0 ? max($index + $fromIndex, 1) : min($fromIndex + 1, $index);
        }

        $keys = array_keys($this->items);

        while (--$index >= 0) {
            $key = $keys[$index];
            yield $key => $this->items[$key];
        }
    }
Reverse iterate through the items starting at the given index.

@param int $fromIndex The starting index to search from. Default is the last index.
Can be negative to start from that far from the end of the array.
If index is out of bounds, it will be moved to first/last index.

@return \Generator