PHP code example of xtompie / flow

1. Go to this page and download the library: Download xtompie/flow 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/ */

    

xtompie / flow example snippets




$animals = ['rat', 'cat', 'lion', 'puma', 'dog'];

// alfabetic 
sort($animals);

// pets
$animalPets = [];
$pets = ['cat', 'dog', 'rat'];
foreach ($animals as $animal) {
    if (in_array($animal, $pets)) {
        $animalPets = $animal; 
    }
}
$animals = $animalPets;

// pretty
foreach ($animals as $index => $animal) {
    $animals[$index] = ucfirst($animal);
}

// first
print_r($animals->get());



use Xtompie\Flow\Flow;
use Xtompie\Flow\FlowFilter;
use Xtompie\Flow\FlowGet;
use Xtompie\Flow\FlowMap;
use Xtompie\Flow\FLowSort;

class Animals
{
    use Flow;
    use FlowFilter;
    use FlowGet;
    use FlowMap;
    use FLowSort;

    public function alfabetic()
    {
        return $this->sort();
    }
    
    public function pets()
    {
        $pets = ['cat', 'dog', 'rat'];
        return $this->filter(function($animal) use ($pets) {
            return in_array($animal, $pets);
        });
    }
    
    public function pretty()
    {
        return $this->map(function($animal) {
            return ucfirst($animal);
        });
    }
}

$animals = (new Animals(['rat', 'cat', 'lion', 'puma', 'dog']))
    ->alfabetic()
    ->pets()
    ->pretty()
;

print_r($animals->get());