PHP code example of slpxxv / stdlib

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

    

slpxxv / stdlib example snippets


use Slpxxv\Stdlib\ArrayCollection;

$values = ArrayCollection::fromIterable(['a' => 1, 'b' => 2, 'c' => 3]);

$result = $values
    ->filter(static fn(int $value): bool => $value > 1)
    ->map(static fn(int $value): int => $value * 10);

$result->toArray(); // ['b' => 20, 'c' => 30]

use Slpxxv\Stdlib\Map\Map;

$map = new Map(['answer' => null]);

$map->has('answer');       // true
$map->get('answer', 42);   // null
$map->get('missing', 42);  // 42
$map->

use Slpxxv\Stdlib\Set\Set;

$left = new Set([1, 2]);
$right = new Set([2, 3]);

$left->union($right)->all();     // [1, 2, 3]
$left->intersect($right)->all(); // [2]
$left->diff($right)->all();      // [1]

use Slpxxv\Stdlib\LazySequence;

$lines = new LazySequence(static function (): iterable {
    $file = new SplFileObject('large.csv');

    foreach ($file as $line) {
        yield $line;
    }
});

$firstTenNonEmptyLines = $lines
    ->filter(static fn(string $line): bool => trim($line) !== '')
    ->take(10)
    ->toArray();

use Slpxxv\Stdlib\XML\CanonicalizationAlgorithm;
use Slpxxv\Stdlib\XML\XmlCanonicalizer;

$canonicalXml = XmlCanonicalizer::canonicalize(
    $document,
    CanonicalizationAlgorithm::Exclusive,
);