PHP code example of jgswift / filtratr

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

    

jgswift / filtratr example snippets


$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->filter('equals',['bar']);

var_dump($filter()); // ['foo' => 'bar']

$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->is('equals',['bar']);

var_dump($filter()); // ['foo' => 'bar']

$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->not('equals',['bar']);

var_dump($filter()); // ['boo' => 'baz']

$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->is(function($val) {
    if($val === 'bar') {
        return true;
    }
});

var_dump($filter()); // ['foo' => 'bar']

$filter = filtratr\with([
    'foo' => 'bar',
    'bar' => 'baz'
])->is('foo', function($val) {
    if($val === 'bar') {
        return true;
    }
});

var_dump($filter()); // ['foo' => 'bar', 'bar' => 'baz']

$filter = filtratr\with([
    'foo' => ' bar ',
    'fiz' => ' buz '
])->map(function($val) {
    return trim($val);
});

var_dump($filter()); // ['foo' => 'bar', 'fiz' => 'buz']

\filtratr\with([
    'foo' => ' bar ',
    'fiz' => ' buz '
])->map('trim');

var_dump($filter()); // ['foo' => 'bar', 'fiz' => 'buz']

$filter = filtratr\with([
    'foo' => ' bar ',
    'bar' => ' baz '
])->map('foo', 'trim');

var_dump($filter()); // ['foo' => 'bar', 'bar' => ' baz ']

$filter = filtratr\with([
    'foo' => ' bar',
    'fiz' => 'buz '
])
->map('trim | strtoupper');

var_dump($filter()); // ['foo' => 'BAR', 'fiz' => 'BUZ']

$filter = filtratr\with([
    'foo' => ' bar',
    'fiz' => 'buz '
])
->map('trim')
->map('strtoupper');

var_dump($filter()); // ['foo' => 'BAR', 'fiz' => 'BUZ']

$filter = filtratr\with([
    1, 2, 3, 4
])->reduce(function($a,$b) {
    return $a * $b;
});

var_dump($filter()[0]); // 24

class User {
    public $name;

    function __construct($name) {
        $this->name = $name;
    }
}

$user = new User(' john smith ');

$filter = filtratr\with($user)->map('name', 'trim | strtoupper')

var_dump($filter()->name); // "JOHN SMITH"

namespace MyQueryExtension;

class MyExtension extends filtratr\Query\AbstractStatement {
    /* do stuff here */
}

$filter = new filtratr\with([
    'foo' => 'bar'
])
->extend('MyQueryExtension')
->myextension();

var_dump($filter());

filtratr\extend('MyQueryExtension');

$filter = new filtratr\with([
    'foo' => 'bar'
])
->myextension();

var_dump($filter());

sh
php composer.phar 
array_reduce