PHPackages                             me-io/php-lodash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. me-io/php-lodash

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

me-io/php-lodash
================

A full-on PHP manipulation utility-belt that provides support for the usual functional.

2.0.0(7y ago)38100.0k↓11%5[1 issues](https://github.com/me-io/php-lodash/issues)MITPHPPHP &gt;=7.1

Since Feb 16Pushed 7y ago6 watchersCompare

[ Source](https://github.com/me-io/php-lodash)[ Packagist](https://packagist.org/packages/me-io/php-lodash)[ RSS](/packages/me-io-php-lodash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (13)Used By (0)

 PHP Lodash
============

[](#--php-lodash)

php-lodash is a PHP utility library, similar to Underscore/Lodash, that utilizes `namespace`s and dynamic auto loading to improve library performance.

---

[![Build Status](https://camo.githubusercontent.com/791b93491c192ca372cd05f86b361a3d6b80e1de6ff0d1419c7f486910469c92/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d652d696f2f7068702d6c6f646173682e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/me-io/php-lodash)[![Code Cov](https://camo.githubusercontent.com/2458d0f0ff3b5d5cadb9dafb9c0017dbed3db30e4f6239b1c478e7a7b799ec56/68747470733a2f2f636f6465636f762e696f2f67682f6d652d696f2f7068702d6c6f646173682f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/me-io/php-lodash)[![Scrutinizer](https://camo.githubusercontent.com/a06d3de566072131b5391f79e770f8919e930f4263c7df64136c743d3ea409f3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d652d696f2f7068702d6c6f646173682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/me-io/php-lodash/?branch=master)[![downloads](https://camo.githubusercontent.com/08cacc4d89fb8eeff40e65e946381e233595958acb7703d9e62680197b26ebcb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d652d696f2f7068702d6c6f646173682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/me-io/php-lodash/stats)[![MIT License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/me-io/php-lodash/blob/master/LICENSE.md)[![SymfonyInsight](https://camo.githubusercontent.com/dbd23e7e3be5aa456afb8016e42aad5a9965c13a5d9e97a8750d33de728a56bd/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f36386634333166312d616261322d343138392d616165622d3061363533313033383939372f6d696e692e737667)](https://insight.symfony.com/projects/68f431f1-aba2-4189-aaeb-0a6531038997)

[![All Contributors](https://camo.githubusercontent.com/db0a672758a6b3f2641e6c6099e3fadfd608167acfae3b31425eb3917b0dc47f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c5f636f6e7472696275746f72732d322d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](#contributors)[![PRs Welcome](https://camo.githubusercontent.com/25b3e6d0d42c98de74a98cbb4d149a1c09020cf6d1361993b72d7d5b8ffed363/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://makeapullrequest.com)[![Code of Conduct](https://camo.githubusercontent.com/6cf3a420df991efb9d5319bcf31f1aec6d12e660e25f13256cb256e76a4399a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306f662d636f6e647563742d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://github.com/me-io/php-lodash/blob/master/CODE_OF_CONDUCT.md)[![Watch on GitHub](https://camo.githubusercontent.com/a10b760c114caa5e96ebd7716f9fcb2f22de9ff60c9d1882bce47ece7516b405/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6d652d696f2f7068702d6c6f646173682e7376673f7374796c653d736f6369616c)](https://github.com/me-io/php-lodash/watchers)[![Star on GitHub](https://camo.githubusercontent.com/712685f65bf29bf6e709fe7e44ec4d337bb78e4a0c7f0e4192e074704f17ad87/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6d652d696f2f7068702d6c6f646173682e7376673f7374796c653d736f6369616c)](https://github.com/me-io/php-lodash/stargazers)[![Tweet](https://camo.githubusercontent.com/e69d0c89ef4cb62d58ed2ddbf344e8494bbf76e1834bc2ff919686c372d52da0/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f68747470732f6769746875622e636f6d2f6d652d696f2f7068702d6c6f646173682e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Check%20out%20php-lodash!%20https://github.com/me-io/php-lodash%20%F0%9F%91%8D)[![Donate](https://camo.githubusercontent.com/21b9b3571c7f2fc583ad6b1b49aeb1524dd82f18a1b2e83c005c570cb71816ab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d3137394244372e7376673f7374796c653d666c61742d73717561726573)](https://www.paypal.me/meabed)

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Installation](#installation)
- [Structure](#structure)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)

Requirements
------------

[](#requirements)

This library requires php `php_mbstring` extension. To enable this extension open your `php.ini` file and find for the line `extension=php_mbstring.dll` and uncomment it. If this line is not there then manually add this line in `php.ini`.

```
extension=php_mbstring.dll
```

Introduction
------------

[](#introduction)

`lodash-php` is a PHP utility library, similar to `Underscore/Lodash`, that utilizes `namespace`s and dynamic auto loading to improve library performance.

### Project Structure

[](#project-structure)

- `__.php` is the entry point for the `lodash-php` utility library
- All lodash-php methods are stored in separate files within their respective `namespace` folder outlined in `/src/__`
- Tests reflect the `namespace` defined within the library and are processed using [phpunit testing](https://phpunit.de)
    - To run tests run the following command `phpunit`

```
.
├── images                               # Place relevant graphics in this folder
├── src                                  # Core code of the application.
│   ├── __.php                           # Entry point for the library
│   └── Traits                           # Contains all lodash-php methods
│       ├── Sequence\Chain.php           # Methods related to chaining
│       ├── Sequence\ChainWrapper.php    # Methods related to chaining
│       ├── Arrays.php                   # Methods related to arrays
│       ├── Collections.php              # Methods related to collections
│       ├── Functions.php                # Methods related to functions
│       ├── Objects.php                  # Methods related to objects
│       ├── Strings.php                  # Methods related to strings
│       └── Utilities.php                # Methods related to utilities
├── tests                                # Tests are placed in that folder.
├── composer.json                        # This file defines the project requirements
├── phpcs.xml.dist                       # Contains the configuration for PHPcs.
├── phpstan.neon.dist                    # Contains the configuration for PHPStan.
├── phpunit.xml.dist                     # Contains the configuration for PHPUnit.
├── LICENSE                              # License file for `lodash-php`
└── README.md                            # Introduces our library to user.
```

---

 **NOTE:** lodash-php is not currently in feature parity with Underscore/Lodash. Review the [contributing](#contributing) section for more information.

---

Installation
------------

[](#installation)

Just add `me-io/php-lodash` to your project composer.json file:

```
{
    "require": {
        "me-io/php-lodash": "^2"
    }
}
```

and then run composer install. This will install `me-io/php-lodash` and all it's dependencies. Or run the following command:

```
composer require me-io/php-lodash
```

Usage
-----

[](#usage)

### Arrays

[](#arrays)

##### [`__::append(array $array = [], $value = null)`](src/Traits/Arrays.php)

[](#__appendarray-array---value--null)

Append item to array

```
__::append([1, 2, 3], 4);
# [1, 2, 3, 4]
```

##### [`__::compact(array $array = [])`](src/Traits/Arrays.php)

[](#__compactarray-array--)

Returns a copy of the array with falsy values removed.

```
__::compact([0, 1, false, 2, '', 3]);
# [1, 2, 3]
```

##### [`__::flatten($array, $shallow = false)`](src/Traits/Arrays.php)

[](#__flattenarray-shallow--false)

Flattens a multidimensional array. If you pass shallow, the array will only be flattened a single level.

```
__::flatten([1, 2, [3, [4]]], [flatten]);
# [1, 2, 3, 4]
```

##### [`__::patch($arr, $patches, $parent = '')`](src/Traits/Arrays.php)

[](#__patcharr-patches-parent--)

Patches array with list of xpath-value pairs.

```
__::patch(['addr' => ['country' => 'US', 'zip' => 12345]], ['/addr/country' => 'CA', '/addr/zip' => 54321]);
# ['addr' => ['country' => 'CA', 'zip' => 54321]]
```

##### [`__::prepend(array $array = [], $value = null)`](src/Traits/Arrays.php)

[](#__prependarray-array---value--null)

```
__::prepend([1, 2, 3], 4);
# [4, 1, 2, 3]
```

##### [`__::range($start = null, $stop = null, $step = 1)`](src/Traits/Arrays.php)

[](#__rangestart--null-stop--null-step--1)

Returns an array of integers from start to stop (exclusive) by step.

```
__::range(1, 10, 2);
# [1, 3, 5, 7, 9]
```

##### [`__::repeat($object = '', $times = null)`](src/Traits/Arrays.php)

[](#__repeatobject---times--null)

Returns an array of `$n` length with each index containing the provided value.

```
__::repeat('foo', 3);
# ['foo', 'foo', 'foo']
```

#### [`__::chunk(array $array, $size = 1, $preserveKeys = false)`](src/Traits/Arrays.php)

[](#__chunkarray-array-size--1-preservekeys--false)

Split an array into chunks

```
__::chunk([1, 2, 3, 4, 5], 3);
# [[1, 2, 3], [4, 5]]
```

#### [`__::drop(array $input, $number = 1)`](src/Traits/Arrays.php)

[](#__droparray-input-number--1)

Creates a slice of array with n elements dropped from the beginning.

```
__::drop([0, 1, 3], 2);
# [3]
```

#### [`__::randomize(array $array)`](src/Traits/Arrays.php)

[](#__randomizearray-array)

Shuffle an array ensuring no item remains in the same position.

```
__::randomize([1, 2, 3]);
# [2, 3, 1]
```

#### [`__::search($array, $value)`](src/Traits/Arrays.php)

[](#__searcharray-value)

Search for the index of a value in an array.

```
__::search(['a', 'b', 'c'], 'b');
# 1
```

#### [`__::average($array, $decimals)`](src/Traits/Arrays.php)

[](#__averagearray-decimals)

Returns the average value of an array.

```
__::average([1, 2, 3]);
# 2
```

#### [`__::size($array)`](src/Traits/Arrays.php)

[](#__sizearray)

Get the size of an array.

```
__::size([1, 2, 3]);
# 3
```

#### [`__::contains($array, $value)`](src/Traits/Arrays.php)

[](#__containsarray-value)

Check if an item is in an array.

```
__::contains(['a', 'b', 'c'], 'b');
# true
```

#### [`__::clean(array $array)`](src/Traits/Arrays.php)

[](#__cleanarray-array)

Clean all falsy values from an array.

```
__::clean([true, false, 0, 1, 'string', '']);
# [true, 1, 'string']
```

#### [`__::random(array $array, $take = null)`](src/Traits/Arrays.php)

[](#__randomarray-array-take--null)

Get a random string from an array.

```
__::random([1, 2, 3]);
# Returns 1, 2 or 3
```

#### [`__::intersection(array $a, array $b)`](src/Traits/Arrays.php)

[](#__intersectionarray-a-array-b)

Return an array with all elements found in both input arrays.

```
__::intersection(["green", "red", "blue"], ["green", "yellow", "red"]);
# ["green", "red"]
```

#### [`__::intersects(array $a, array $b)`](src/Traits/Arrays.php)

[](#__intersectsarray-a-array-b)

Return a boolean flag which indicates whether the two input arrays have any common elements.

```
__::intersects(["green", "red", "blue"], ["green", "yellow", "red"])
# true
```

#### [`__::initial(array $array, int $to = 1)`](src/Traits/Arrays.php)

[](#__initialarray-array-int-to--1)

Exclude the last X elements from an array

```
__::initial([1, 2, 3], 1);
# [1, 2]
```

#### [`__::rest(array $array, int $from = 1)`](src/Traits/Arrays.php)

[](#__restarray-array-int-from--1)

Exclude the first X elements from an array

```
__::rest([1, 2, 3], 2);
# [3]
```

#### [`__::sortKeys(array $array, string $direction = 'ASC')`](src/Traits/Arrays.php)

[](#__sortkeysarray-array-string-direction--asc)

Sort an array by key.

```
__::sortKeys(['z' => 0, 'b' => 1, 'r' => 2]);
# ['b' => 1, 'r' => 2, 'z' => 0]

__::sortKeys(['z' => 0, 'b' => 1, 'r' => 2], 'desc');
# ['z' => 0, 'r' => 2, 'b' => 1]
```

#### [`____::without(array $array, $remove, $preserveKeys = false)`](src/Traits/Arrays.php)

[](#____withoutarray-array-remove-preservekeys--false)

Remove unwanted values from array

Returns new array without preserving keys.

```
__::without([1, 1 => 3, 2 => 4, 5], 4)
# [0 => 1, 1 => 3, 2 => 5]
```

Returns new array with preserving keys.

```
__::without([1, 3 => 3, 2 => 4, 5], 4, true)
# [0 => 1, 3 => 3, 4 => 5]
```

### Chaining

[](#chaining)

#### [`__::chain($initialValue)`](src/Traits/Sequence/Chain.php)

[](#__chaininitialvalue)

Returns a wrapper instance, allows the value to be passed through multiple php-lodash functions

```
__::chain([0, 1, 2, 3, null])
    ->compact()
    ->prepend(4)
    ->value();
# [4, 1, 2, 3]
```

### Collections

[](#collections)

##### [`__::filter($array, callback($n))`](src/Traits/Collections.php)

[](#__filterarray-callbackn)

Returns the values in the collection that pass the truth test.

```
$a = [
    ['name' => 'fred',   'age' => 32],
    ['name' => 'maciej', 'age' => 16]
];

__::filter($a, function($n) {
    return $n['age'] > 24;
});
# [['name' => 'fred', 'age' => 32]]
```

##### [`__::first($array, [$n])`](src/Traits/Collections.php)

[](#__firstarray-n)

Gets the first element of an array. Passing n returns the first n elements.

```
__::first([1, 2, 3, 4, 5], 2);
# [1, 2]
```

##### [`__::get($array, JSON $string)`](src/Traits/Collections.php)

[](#__getarray-json-string)

Get item of an array by index, aceepting nested index

```
__::get(['foo' => ['bar' => 'ter']], 'foo.bar');
# 'ter'
```

##### [`__::last($array, [$n])`](src/Traits/Collections.php)

[](#__lastarray-n)

Gets the last element of an array. Passing n returns the last n elements.

```
__::last([1, 2, 3, 4, 5], 2);
# [4, 5]
```

##### [`__::map($array, callback($n))`](src/Traits/Collections.php)

[](#__maparray-callbackn)

Returns an array of values by mapping each in collection through the iterator.

```
__::map([1, 2, 3], function($n) {
    return $n * 3;
});
# [3, 6, 9]
```

##### [`__::max($array)`](src/Traits/Collections.php)

[](#__maxarray)

Returns the maximum value from the collection. If passed an iterator, max will return max value returned by the iterator.

```
__::max([1, 2, 3]);
# 3
```

##### [`__::min($array)`](src/Traits/Collections.php)

[](#__minarray)

Returns the minimum value from the collection. If passed an iterator, min will return min value returned by the iterator.

```
__::min([1, 2, 3]);
# 1
```

##### [`__::pluck($array, $property)`](src/Traits/Collections.php)

[](#__pluckarray-property)

Returns an array of values belonging to a given property of each item in a collection.

```
$a = [
    ['foo' => 'bar',  'bis' => 'ter' ],
    ['foo' => 'bar2', 'bis' => 'ter2'],
];

__::pluck($a, 'foo');
# ['bar', 'bar2']
```

##### [`__::where($array, $parameters[])`](src/Traits/Collections.php)

[](#__wherearray-parameters)

Returns a collection of objects matching the given array of parameters.

```
$a = [
    ['name' => 'fred',   'age' => 32],
    ['name' => 'maciej', 'age' => 16]
];

__::where($a, ['age' => 16]);
# [['name' => 'maciej', 'age' => 16]]
```

#### [`__::assign($collection1, $collection2)`](src/Traits/Collections.php)

[](#__assigncollection1-collection2)

Combines and merge collections provided with each others.

```
$a = [
    'color' => [
        'favorite' => 'red',
        5
    ],
    3
];
$b = [
    10,
    'color' => [
        'favorite' => 'green',
        'blue'
    ]
];

__::assign($a, $b);
# ['color' => ['favorite' => 'green', 'blue'], 10]
```

#### [`__::reduceRight($collection, \Closure $iteratee, $accumulator = null)`](src/Traits/Collections.php)

[](#__reducerightcollection-closure-iteratee-accumulator--null)

Reduces $collection to a value which is the $accumulator result of running each element in $collection - from right to left - thru $iteratee, where each successive invocation is supplied the return value of the previous.

```
__::reduceRight(['a', 'b', 'c'], function ($word, $char) {
    return $word . $char;
}, '');
# 'cba'
```

#### [`__::doForEachRight($collection, \Closure $iteratee)`](src/Traits/Collections.php)

[](#__doforeachrightcollection-closure-iteratee)

Iterate over elements of the collection, from right to left, and invokes iterate for each element.

```
__::doForEachRight([1, 2, 3], function ($value) { print_r($value) });
# (Side effect: print 3, 2, 1)
```

#### [`__::doForEach($collection, \Closure $iteratee)`](src/Traits/Collections.php)

[](#__doforeachcollection-closure-iteratee)

Iterate over elements of the collection and invokes iterate for each element.

```
__::doForEach([1, 2, 3], function ($value) { print_r($value) });
# (Side effect: print 1, 2, 3)
```

#### [`__::set($collection, $path, $value = null)`](src/Traits/Collections.php)

[](#__setcollection-path-value--null)

Return a new collection with the item set at index to given value. Index can be a path of nested indexes.

```
__::set(['foo' => ['bar' => 'ter']], 'foo.baz.ber', 'fer');
# '['foo' => ['bar' => 'ter', 'baz' => ['ber' => 'fer']]]'
```

#### [`__::hasKeys($collection, $path, $value = null)`](src/Traits/Collections.php)

[](#__haskeyscollection-path-value--null)

Returns if $input contains all requested $keys. If $strict is true it also checks if $input exclusively contains the given $keys.

```
__::hasKeys(['foo' => 'bar', 'foz' => 'baz'], ['foo', 'foz']);
# true
```

#### [`__::has($collection, $path)`](src/Traits/Collections.php)

[](#__hascollection-path)

Return true if $collection contains the requested $key.

```
__::has(['foo' => ['bar' => 'num'], 'foz' => 'baz'], 'foo.bar');
# true

__::hasKeys((object) ['foo' => 'bar', 'foz' => 'baz'], 'bar');
# false
```

#### [`__::concat($collection1, $collection2)`](src/Traits/Collections.php)

[](#__concatcollection1-collection2)

Combines and concat collections provided with each others.

```
__::concat(['color' => ['favorite' => 'red', 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]);
# ['color' => ['favorite' => ['green'], 5, 'blue'], 3, 10]
```

#### [`__::concatDeep($collection1, $collection2)`](src/Traits/Collections.php)

[](#__concatdeepcollection1-collection2)

Recursively combines and concat collections provided with each others.

```
__::concatDeep(['color' => ['favorite' => 'red', 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]);
# ['color' => ['favorite' => ['red', 'green'], 5, 'blue'], 3, 10]
```

#### [`__::ease(array $collection, $glue = '.')`](src/Traits/Collections.php)

[](#__easearray-collection-glue--)

Flattens a complex collection by mapping each ending leafs value to a key consisting of all previous indexes.

```
__::ease(['foo' => ['bar' => 'ter'], 'baz' => ['b', 'z']]);
# '['foo.bar' => 'ter', 'baz.0' => 'b', , 'baz.1' => 'z']'
```

#### [`__::every($collection, \Closure $iteratee)`](src/Traits/Collections.php)

[](#__everycollection-closure-iteratee)

Checks if predicate returns truthy for all elements of collection.

```
__::every([1, 3, 4], function ($v) { return is_int($v); });
// → true
```

#### [`__::groupBy(array $array, $key)`](src/Traits/Collections.php)

[](#__groupbyarray-array-key)

Returns an associative array where the keys are values of $key.

```
__::groupBy([
        ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus'],
        ['state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb'],
        ['state' => 'CA', 'city' => 'Mountain View', 'object' => 'Space pen'],
    ],
    'state'
);
# [
#   'IN' => [
#       ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus'],
#       ['state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb'],
#   ],
#   'CA' => [
#       ['state' => 'CA', 'city' => 'Mountain View', 'object' => 'Space pen']
#    ]
# ]

__::groupBy([
        ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus'],
        ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'Manhole'],
        ['state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb'],
    ],
    function ($value) {
        return $value->city;
    }
);
# [
#   'Indianapolis' => [
#     ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus'],
#     ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'Manhole'],
#   ],
#   'San Diego' => [
#     ['state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb'],
#   ]
# ]
```

#### [`__::isEmpty($value)`](src/Traits/Collections.php)

[](#__isemptyvalue)

Check if value is an empty array or object.

```
__::isEmpty([]);
# true
```

#### [`__::merge($collection1, $collection2)`](src/Traits/Collections.php)

[](#__mergecollection1-collection2)

Recursively combines and merge collections provided with each others.

```
__::merge(['color' => ['favorite' => 'red', 'model' => 3, 5], 3], [10, 'color' => ['favorite' => 'green', 'blue']]);
# ['color' => ['favorite' => 'green', 'model' => 3, 'blue'], 10]
```

#### [`__::pick($collection = [], array $paths = [], $default = null)`](src/Traits/Collections.php)

[](#__pickcollection---array-paths---default--null)

Returns an array having only keys present in the given path list.

```
__::pick(['a' => 1, 'b' => ['c' => 3, 'd' => 4]], ['a', 'b.d']);
# ['a' => 1, 'b' => ['d' => 4]]
```

#### [`__::reduce($collection, \Closure $iteratee, $accumulator = null)`](src/Traits/Collections.php)

[](#__reducecollection-closure-iteratee-accumulator--null)

Reduces $collection to a value which is the $accumulator result of running each element in $collection thru $iteratee, where each successive invocation is supplied the return value of the previous.

```
__::reduce([1, 2], function ($sum, $number) {
    return $sum + $number;
}, 0);
# 3

$a = [
    ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus'],
    ['state' => 'IN', 'city' => 'Indianapolis', 'object' => 'Manhole'],
    ['state' => 'IN', 'city' => 'Plainfield', 'object' => 'Basketball'],
    ['state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb'],
    ['state' => 'CA', 'city' => 'Mountain View', 'object' => 'Space pen'],
];
$iteratee = function ($accumulator, $value) {
    if (isset($accumulator[$value['city']]))
        $accumulator[$value['city']]++;
    else
        $accumulator[$value['city']] = 1;
    return $accumulator;
};
__::reduce($c, $iteratee, []);
# [
#    'Indianapolis' => 2,
#    'Plainfield' => 1,
#    'San Diego' => 1,
#    'Mountain View' => 1,
# ]

$object = new \stdClass();
$object->a = 1;
$object->b = 2;
$object->c = 1;
__::reduce($object, function ($result, $value, $key) {
    if (!isset($result[$value]))
        $result[$value] = [];
    $result[$value][] = $key;
    return $result;
}, [])
# [
#     '1' => ['a', 'c'],
#     '2' => ['b']
# ]
```

#### [`__::unease(array $collection, $separator = '.')`](src/Traits/Collections.php)

[](#__uneasearray-collection-separator--)

Builds a multidimensional collection out of a hash map using the key as indicator where to put the value.

```
__::unease(['foo.bar' => 'ter', 'baz.0' => 'b', , 'baz.1' => 'z']);
# '['foo' => ['bar' => 'ter'], 'baz' => ['b', 'z']]'
```

### Strings

[](#strings)

#### [`__::split($input, $delimiter, $limit = PHP_INT_MAX)`](src/Traits/Strings.php)

[](#__splitinput-delimiter-limit--php_int_max)

Split a string by string.

```
__::split('a-b-c', '-', 2);
# ['a', 'b-c']
```

#### [`__::camelCase($input)`](src/Traits/Strings.php)

[](#__camelcaseinput)

Converts string to [camel case](https://en.wikipedia.org/wiki/CamelCase).

```
__::camelCase('Foo Bar');
# 'fooBar'
```

#### [`__::capitalize($input)`](src/Traits/Strings.php)

[](#__capitalizeinput)

Converts the first character of string to upper case and the remaining to lower case.

```
__::capitalize('FRED');
# 'Fred'
```

#### [`__::kebabCase($input)`](src/Traits/Strings.php)

[](#__kebabcaseinput)

Converts string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).

```
__::kebabCase('Foo Bar');
# 'foo-bar'
```

#### [`__::lowerFirst($input)`](src/Traits/Strings.php)

[](#__lowerfirstinput)

Converts the first character of string to lower case, like lcfirst.

```
__::lowerFirst('Fred');
# 'fred'
```

#### [`__::snakeCase($input)`](src/Traits/Strings.php)

[](#__snakecaseinput)

Converts string to [snake case](https://en.wikipedia.org/wiki/Snake_case).

```
__::snakeCase('Foo Bar');
# 'foo_bar'
```

#### [`__::startCase($input)`](src/Traits/Strings.php)

[](#__startcaseinput)

Converts string to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).

```
__::startCase('--foo-bar--');
# 'Foo Bar'
```

#### [`__::toLower($input)`](src/Traits/Strings.php)

[](#__tolowerinput)

Converts string, as a whole, to lower case just like strtolower.

```
__::toLower('fooBar');
# 'foobar'
```

#### [`__::toUpper($input)`](src/Traits/Strings.php)

[](#__toupperinput)

Converts string, as a whole, to lower case just like strtoupper.

```
__::toUpper('fooBar');
# 'FOOBAR'
```

#### [`__::upperCase($input)`](src/Traits/Strings.php)

[](#__uppercaseinput)

Converts string, as space separated words, to upper case.

```
__::upperCase('--foo-bar');
# 'FOO BAR'
```

#### [`__::upperFirst($input)`](src/Traits/Strings.php)

[](#__upperfirstinput)

Converts the first character of string to upper case, like ucfirst.

```
__::upperFirst('fred');
# 'Fred'
```

#### [`__::words($input, $pattern = null)`](src/Traits/Strings.php)

[](#__wordsinput-pattern--null)

Splits string into an array of its words.

```
__::words('fred, barney, & pebbles');
# ['fred', 'barney', 'pebbles']

__::words('fred, barney, & pebbles', '/[^, ]+/');
# ['fred', 'barney', '&', 'pebbles']
```

#### [`__::lowerCase($input)`](src/Traits/Strings.php)

[](#__lowercaseinput)

Converts string, as space separated words, to lower case.

```
__::lowerCase('--Foo-Bar--');
# 'foo bar'
```

### Functions

[](#functions)

##### [`__::slug($string, [array $options])`](src/Traits/Functions.php)

[](#__slugstring-array-options)

```
__::slug('Jakieś zdanie z dużą ilością obcych znaków!');
# 'jakies-zdanie-z-duza-iloscia-obcych-znakow'

$options = [
    'delimiter' => '-',
    'limit' => 30,
    'lowercase' => true,
    'replacements' => array(),
    'transliterate' => true
]

__::slug('Something you don\'t know about know about Jackson', $options);
# 'something-you-dont-know-about'
```

##### [`__::truncate($string, [$limit=40])`](src/Traits/Functions.php)

[](#__truncatestring-limit40)

Truncate string based on count of words

```
$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et mi orci.';
__::truncate($string);
# 'Lorem ipsum dolor sit amet, consectetur...'

__::truncate($string, 60);
# 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pel...'
```

##### [`__::urlify($string)`](src/Traits/Functions.php)

[](#__urlifystring)

Find the urls inside a string a put them inside anchor tags

```
__::urlify('I love https://google.com');
# 'I love google.com'
```

### Objects

[](#objects)

##### [`__::isArray($array)`](src/Traits/Objects.php)

[](#__isarrayarray)

Check if give value is array or not.

```
__::isArray([1, 2, 3]);
# true

__::isArray(123);
# false
```

##### [`__::isFunction($string)`](src/Traits/Objects.php)

[](#__isfunctionstring)

Check if give value is function or not.

```
__::isFunction(function ($a) { return $a + 2; });
# true
```

##### [`__::isNull($null)`](src/Traits/Objects.php)

[](#__isnullnull)

Check if give value is null or not.

```
__::isNull(null);
# true
```

##### [`__::isNumber($int|$float)`](src/Traits/Objects.php)

[](#__isnumberintfloat)

Check if give value is number or not.

```
__::isNumber(123);
# true
```

##### [`__::isObject($object)`](src/Traits/Objects.php)

[](#__isobjectobject)

Check if give value is object or not.

```
__::isObject('fred');
# false
```

##### [`__::isString($string)`](src/Traits/Objects.php)

[](#__isstringstring)

Check if give value is string or not.

```
__::isString('fred');
# true
```

### Utilities

[](#utilities)

##### [`__::isEmail($string)`](src/Traits/Objects.php)

[](#__isemailstring)

Check if the value is valid email.

```
__::isEmail('test@test.com');
# true

__::isEmail('test_test.com');
# false
```

##### [`__::now()`](src/Traits/Utilities.php)

[](#__now)

Wrapper of the [`time()`](http://php.net/manual/en/function.time.php) function that returns the current offset in seconds since the Unix Epoch.

```
__::now();
# 1417546029
```

##### [`__::stringContains($needle, $haystack, [$offset])`](src/Traits/Utilities.php)

[](#__stringcontainsneedle-haystack-offset)

Wrapper of the [`time()`](http://php.net/manual/en/function.time.php) function that returns the current offset in seconds since the Unix Epoch.

```
__::stringContains('waffle', 'wafflecone');
# true
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please feel free to contribute to this project! Pull requests and feature requests welcome! ✌️

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Contributors
------------

[](#contributors)

A huge thanks to all of our contributors:

[![](https://avatars0.githubusercontent.com/u/45731?v=3)
**Mohamed Meabed**](https://github.com/Meabed)
[💻](https://github.com//php-lodash/commits?author=Meabed "Code") [⚠️](https://github.com//php-lodash/commits?author=Meabed "Tests") [📢](#talk-Meabed "Talks")[![](https://avatars2.githubusercontent.com/u/16267321?v=3)
**Zeeshan Ahmad**](https://github.com/ziishaned)
[💻](https://github.com//php-lodash/commits?author=ziishaned "Code") [🐛](https://github.com//php-lodash/issues?q=author%3Aziishaned "Bug reports") [⚠️](https://github.com//php-lodash/commits?author=ziishaned "Tests") [📖](https://github.com//php-lodash/commits?author=ziishaned "Documentation")License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~63 days

Total

8

Last Release

2672d ago

Major Versions

1.1.1 → 2.0.02019-01-24

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0688fa386c5dbcbb27c78b325cf9a957ddf8b07c3bf53271060e2a32aa91975?d=identicon)[meabed](/maintainers/meabed)

---

Top Contributors

[![meabed](https://avatars.githubusercontent.com/u/45731?v=4)](https://github.com/meabed "meabed (35 commits)")[![ziishaned](https://avatars.githubusercontent.com/u/16267321?v=4)](https://github.com/ziishaned "ziishaned (23 commits)")[![Idnan](https://avatars.githubusercontent.com/u/6161794?v=4)](https://github.com/Idnan "Idnan (4 commits)")[![zeeshanbashir](https://avatars.githubusercontent.com/u/6536027?v=4)](https://github.com/zeeshanbashir "zeeshanbashir (1 commits)")

---

Tags

helperslodashphp7underscoreutilitiesutilitylibraryfunctionslodashbottomline

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/me-io-php-lodash/health.svg)

```
[![Health](https://phpackages.com/badges/me-io-php-lodash/health.svg)](https://phpackages.com/packages/me-io-php-lodash)
```

###  Alternatives

[maciejczyzewski/bottomline

A full-on PHP manipulation utility belt that provides support for working with arrays, objects, and iterables; a lodash or underscore equivalent for PHP.

477631.4k10](/packages/maciejczyzewski-bottomline)[tajawal/lodash-php

A full-on PHP manipulation utility-belt that provides support for the usual functional.

232.6k1](/packages/tajawal-lodash-php)[lodash-php/lodash-php

A port of Lodash to PHP

527719.0k5](/packages/lodash-php-lodash-php)[mpetrovich/dash

A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.

10428.9k1](/packages/mpetrovich-dash)[kisma/kisma

PHP Utility Belt

178.5k8](/packages/kisma-kisma)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
