PHP code example of mero / utils

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

    

mero / utils example snippets




use Mero\Utils\Collection;

$var = new Collection();
$var[] = 'First element';
$var[] = 'Second element';

$var->count(); // Will return 2



use Mero\Utils\Collection;

$var = new Collection([
    'First element',
    'Second element',
    1,
    4,
    10,
]);

$var->find(function($it) {
    return $it == 'Second element';
}); // Will return 'Second element'



use Mero\Utils\Collection;

$var = new Collection([
    'First element',
    'Second element',
    1,
    4,
    10,
    'Second element',
    'Second element',
]);

$var->findAll(function($it) {
    return $it == 'Second element';
}); // Will return ['Second element', 'Second element', 'Second element']



use Mero\Utils\Collection;

$var = new Collection([1, 2, 3]);

$var->collect(function($it) {
    return $it * 3;
}); // Will return [3, 6, 9]



use Mero\Utils\Collection;

$var = new Collection([1, 2, 3]);

$var->each(function($it) {
    echo $it."\n";
});

// Will return:
// 1
// 2
// 3



use Mero\Utils\Collection;

$var = new Collection(['Element1', 'Element2', 'Element3']);

$var->eachWithIndex(function($it, $index) {
    echo $index." - ".$it."\n";
});

// Will return:
// 0 - Element1
// 1 - Element2
// 2 - Element3