PHP code example of wazsmwazsm / kit

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

    

wazsmwazsm / kit example snippets


use Kit\DotArr;

$arr = [];
DotArr::dotSet($arr, 'foo.bar', 'hello');

var_dump($arr); // result is ['foo' => ['bar' => 'hello']]

use Kit\DotArr;

$arr = ['foo' => ['bar' => 'hello']];
$result = DotArr::dotGet($arr, 'foo.bar');

var_dump($result); // result is hello

$result = DotArr::dotGet($arr, 'foo');

var_dump($result); // result is ['bar' => 'hello']


// 获取值不存在返回默认值
$result = DotArr::dotGet($arr, 'a.b', 'd');

var_dump($result); // result is d


use Kit\DotArr;

$arr = ['foo' => ['bar' => 'hello']];
$result = DotArr::dotHas($arr, 'foo.bar');
var_dump($result); // result is true
$result = DotArr::dotHas($arr, 'a.b');
var_dump($result); // result is false

use Kit\DotArr;

DotArr::setOperator('/');
$arr = [];
DotArr::dotSet($arr, 'foo/bar', 'hello');
$result = DotArr::dotGet($arr, 'foo/bar');
var_dump($result); // result is hello

use Kit\Pipeline;

$pipes = [
    function($payload) {
        return $payload + 1;
    },
    function($payload) {
        return $payload + 2;
    },
    function($payload) {
        return $payload + 3;
    },
];
// 初始化时设置管道
$pipe = new Pipeline($pipes);
// 添加管道
$pipe->pipe(function($payload) {
    return $payload + 4;
});

// 运行管道
$result = $pipe->flow(12);

var_dump($result); // result is 22