PHP code example of dormilich / extended-array-object

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

    

dormilich / extended-array-object example snippets


use Dormilich\Core\ArrayObject;

try {
    $duplicates = ArrayObject::from($_POST['group'])
        ->map(function ($item) {
            return $item['name'];
        })
        ->countValues()
        ->filter(function ($count) {
            return $count > 1;
        })
        ->map(function ($count, $name) {
            return sprintf('%d× %s', $count, $name);
        })
    ;

    if (count($duplicates)) {
        $error_string = 'Duplicate names: ' . $duplicates->join(', ');
    }
}
catch (Exception $exc) {
    error_log($exc->getMessage());
}