PHP code example of claytron5000 / better-arrays

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

    

claytron5000 / better-arrays example snippets

$php
$filtered = array_filter($array, function($x) { return count($x.children) > 0});
$reduced = array_reduce($filtered, function($x) {
    $children = array_map(function($child) { return ["parent" => $child.name, etc, etc ]}, $x);
    
}, []);
$mapped = array_map(function($x) { return new CoolObject($x); }, $reduced);
$php
$arrayOfObjects = new BetterArray($array)
    .filter(function($x) { return count($x.children) > 0;})
    .reduce(function($acc, $x) {
        return array_merge($acc, $x.children);
    }, [])
    .map(function($x) { return new CoolObject($x);})
    .returnArray();
$php
// Object instantiation
$arr = new BetterArray($array);

// Static method
$arr = BetterArray::funcify($array);

// Function wrapper
$arr = betterArray($array);