PHP code example of awssat / array-helper

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

    

awssat / array-helper example snippets


arr([' ', 'hi ', null, '  welcome'])->map('trim')->filter()->get()
>> ['hi', 'welcome']
 
$x = arr(['', 'item', null, 'item2'])->filter()->get()
>> ['item', 'item2']

$x = arr(['item', 'item2', null])
    ->ifContains(null)
        ->filter()
    ->endif()
    ->get()

$x = arr(['item', 'item2', null])
    ->ifContains(null)
        ->filter()
    ->all()

$x = arr(['item ', 'item2'])
    ->do(function() {
        return $this->map('trim');
    })
    ->all()
 
$array->map(function($item) {
         return 'Hello: '. strip_tags($item) . ' !'; 
    });
 
$array->walk(function($item, $key) {
            print "$key: $item<br />\n";
    });

$array->walk(function(&$item, $key) {
            $item = $item * 2;
        });

$array->filter(function($item) {
            return $item > 5;
        });