PHP code example of rocketfellows / tuple

1. Go to this page and download the library: Download rocketfellows/tuple library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rocketfellows / tuple example snippets


composer 

class TupleItem
{
    private $id;

    public function __construct(int $id)
    {
        $this->id = $id;
    }

    public function getId(): int
    {
        return $this->id;
    }
}

use rocketfellows\tuple\Tuple;

class Items extends Tuple
{
    public function __construct(TupleItem ...$items)
    {
        parent::__construct(...$items);
    }

    public function current(): ?TupleItem
    {
        return parent::current();
    }
}

$firstTupleItem = new TupleItem(1);
$secondTupleItem = new TupleItem(2);
$thirdTupleItem = new TupleItem(3);

$items = new Items($firstTupleItem, $secondTupleItem, $thirdTupleItem);

foreach ($items as $item) {
    print_r($item->getId());
}

1
2
3