PHP code example of amitmerchant / array-utils
1. Go to this page and download the library: Download amitmerchant/array-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/ */
amitmerchant / array-utils example snippets
use Amitmerchant\ArrayUtils\ArrayUtils;
// Map Array → wrapper for [array_map](https://www.php.net/manual/en/function.array-map.php)
$mappedArray = ArrayUtils::getInstance()
->collect([1, 2, 3, 4])
->map(function($iteration) {
return $iteration * 2;
});
print_r($mappedArray);
/*
Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
)
*/
// Filter Array → wrapper for [array_filter](https://www.php.net/manual/en/function.array-filter.php)
$filterArray = ArrayUtils::getInstance()
->collect([1, 2, 3, 4, 5])
->filter(function($iteration) {
return ($iteration & 1);
});
/*
Array
(
[0] => 1
[1] => 3
[2] => 5
)
*/