PHP code example of brenoroosevelt / array-functions

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

    

brenoroosevelt / array-functions example snippets


// Add - Set
function add(array &$set, ...$elements): int
function set(array &$set, $element, $key = null): void

// Count
function all(iterable $items, callable $callback, bool $empty_is_valid = true, int $mode = CALLBACK_USE_VALUE): bool
function at_least(int $n, iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): bool
function at_most(int $n, iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): bool
function exactly(int $n, iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): bool
function none(iterable $items, callable $callback, int $mode = 0): bool
function some(iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): bool
function contains(iterable $items, ...$elements): bool

// Filter - Extract
function accept(iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): array
function reject(iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): array
function only(array $items, ...$keys): array
function except(array $items, ...$keys): array
function first(iterable $items, callable $callback, $default = null, int $mode = CALLBACK_USE_VALUE)

// Key - Index
function has(array $haystack, $key, ...$keys): bool
function index_of(iterable $haystack, $element, bool $strict = true)

// Remove - Pull
function pull(array &$set, $key, $default = null)
function remove(array &$set, ...$elements): int
function remove_key(array &$set, $key, ...$keys): int

// Miscellaneous
function map(iterable $items, callable $callback, int $mode = CALLBACK_USE_VALUE): array
function paginate(array $items, int $page, int $per_page, bool $preserve_keys = true): array
function sum(iterable $items, callable $callback, int $mode = 0)

// Dot Notation
function flatten(array $items, ?string $pathSeparator = null): array
function expand(array $items, string $separator = '.'): array
function set_path(array &$haystack, string $path, $value, string $separator = '.'): void
function get_path(array $haystack, string $path, $default = null, string $separator = '.')
function unset_path(array &$haystack, string $path, string $separator = '.')
function has_path(array $haystack, string $path, string $separator = '.'): bool

// Pipeline
function pipe($payload, callable ...$stages)
function with(&$value, callable ...$jobs)