SimplePie::get_items PHP Method

get_items() public method

This is better suited for {@link http://php.net/for for()} loops, whereas {@see \get_items()} is better suited for {@link http://php.net/foreach foreach()} loops.
See also: get_item_quantity
public get_items ( integer $start, integer $end ) : SimplePie_Item[] | null
$start integer Index to start at
$end integer Number of items to return. 0 for all items after `$start`
return SimplePie_Item[] | null List of {@see \SimplePie_Item} objects
    public function get_items($start = 0, $end = 0)
    {
        if (!isset($this->data['items'])) {
            if (!empty($this->multifeed_objects)) {
                $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
                if (empty($this->data['items'])) {
                    return array();
                }
                return $this->data['items'];
            }
            $this->data['items'] = array();
            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) {
                $keys = array_keys($items);
                foreach ($keys as $key) {
                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
                }
            }
            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) {
                $keys = array_keys($items);
                foreach ($keys as $key) {
                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
                }
            }
            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) {
                $keys = array_keys($items);
                foreach ($keys as $key) {
                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
                }
            }
            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) {
                $keys = array_keys($items);
                foreach ($keys as $key) {
                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
                }
            }
            if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) {
                $keys = array_keys($items);
                foreach ($keys as $key) {
                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
                }
            }
        }
        if (empty($this->data['items'])) {
            return array();
        }
        if ($this->order_by_date) {
            if (!isset($this->data['ordered_items'])) {
                $this->data['ordered_items'] = $this->data['items'];
                usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
            }
            $items = $this->data['ordered_items'];
        } else {
            $items = $this->data['items'];
        }
        // Slice the data as desired
        if ($end === 0) {
            return array_slice($items, $start);
        } else {
            return array_slice($items, $start, $end);
        }
    }

Usage Example

 public function getItems()
 {
     $retVal = [];
     foreach ($this->simplePie->get_items() as $item) {
         /** @var \SimplePie_Item[] $item */
         $retVal[] = ['uuid' => $item->get_id(), 'author' => $item->get_author() ? $item->get_author()->get_name() : null, 'title' => $item->get_title(), 'content' => $item->get_content(), 'url' => $item->get_link(), 'date' => ($timeStamp = strtotime($item->get_gmdate())) > 0 ? $timeStamp : time()];
     }
     return $retVal;
 }
All Usage Examples Of SimplePie::get_items