Download the PHP package me-io/php-lodash without Composer
On this page you can find all versions of the php package me-io/php-lodash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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.
Table of Contents
- Introduction
- Installation
- Structure
- Usage
- Contributing
- License
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
.
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
__.php
is the entry point for thelodash-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- To run tests run the following command
phpunit
- To run tests run the following command
NOTE: lodash-php is not currently in feature parity with Underscore/Lodash. Review the contributing section for more information.
Installation
Just add me-io/php-lodash
to your project composer.json file:
and then run composer install. This will install me-io/php-lodash
and all it's dependencies. Or run the following command:
Usage
Arrays
__::append(array $array = [], $value = null)
Append item to array
__::compact(array $array = [])
Returns a copy of the array with falsy values removed.
__::flatten($array, $shallow = false)
Flattens a multidimensional array. If you pass shallow, the array will only be flattened a single level.
Patches array with list of xpath-value pairs.
__::prepend(array $array = [], $value = null)
__::range($start = null, $stop = null, $step = 1)
Returns an array of integers from start to stop (exclusive) by step.
Returns an array of $n
length with each index containing the provided value.
__::chunk(array $array, $size = 1, $preserveKeys = false)
Split an array into chunks
__::drop(array $input, $number = 1)
Creates a slice of array with n elements dropped from the beginning.
__::randomize(array $array)
Shuffle an array ensuring no item remains in the same position.
__::search($array, $value)
Search for the index of a value in an array.
__::average($array, $decimals)
Returns the average value of an array.
__::size($array)
Get the size of an array.
__::contains($array, $value)
Check if an item is in an array.
__::clean(array $array)
Clean all falsy values from an array.
__::random(array $array, $take = null)
Get a random string from an array.
__::intersection(array $a, array $b)
Return an array with all elements found in both input arrays.
__::intersects(array $a, array $b)
Return a boolean flag which indicates whether the two input arrays have any common elements.
__::initial(array $array, int $to = 1)
Exclude the last X elements from an array
__::rest(array $array, int $from = 1)
Exclude the first X elements from an array
Sort an array by key.
____::without(array $array, $remove, $preserveKeys = false)
Remove unwanted values from array
Returns new array without preserving keys.
Returns new array with preserving keys.
Chaining
__::chain($initialValue)
Returns a wrapper instance, allows the value to be passed through multiple php-lodash functions
Collections
__::filter($array, callback($n))
Returns the values in the collection that pass the truth test.
__::first($array, [$n])
Gets the first element of an array. Passing n returns the first n elements.
__::get($array, JSON $string)
Get item of an array by index, aceepting nested index
__::last($array, [$n])
Gets the last element of an array. Passing n returns the last n elements.
__::map($array, callback($n))
Returns an array of values by mapping each in collection through the iterator.
__::max($array)
Returns the maximum value from the collection. If passed an iterator, max will return max value returned by the iterator.
__::min($array)
Returns the minimum value from the collection. If passed an iterator, min will return min value returned by the iterator.
__::pluck($array, $property)
Returns an array of values belonging to a given property of each item in a collection.
__::where($array, $parameters[])
Returns a collection of objects matching the given array of parameters.
__::assign($collection1, $collection2)
Combines and merge collections provided with each others.
__::reduceRight($collection, \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.
__::doForEachRight($collection, \Closure $iteratee)
Iterate over elements of the collection, from right to left, and invokes iterate for each element.
__::doForEach($collection, \Closure $iteratee)
Iterate over elements of the collection and invokes iterate for each element.
__::set($collection, $path, $value = null)
Return a new collection with the item set at index to given value. Index can be a path of nested indexes.
__::hasKeys($collection, $path, $value = null)
Returns if $input contains all requested $keys. If $strict is true it also checks if $input exclusively contains the given $keys.
__::has($collection, $path)
Return true if $collection contains the requested $key.
__::concat($collection1, $collection2)
Combines and concat collections provided with each others.
__::concatDeep($collection1, $collection2)
Recursively combines and concat collections provided with each others.
Flattens a complex collection by mapping each ending leafs value to a key consisting of all previous indexes.
__::every($collection, \Closure $iteratee)
Checks if predicate returns truthy for all elements of collection.
__::groupBy(array $array, $key)
Returns an associative array where the keys are values of $key.
__::isEmpty($value)
Check if value is an empty array or object.
__::merge($collection1, $collection2)
Recursively combines and merge collections provided with each others.
__::pick($collection = [], array $paths = [], $default = null)
Returns an array having only keys present in the given path list.
__::reduce($collection, \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.
Builds a multidimensional collection out of a hash map using the key as indicator where to put the value.
Strings
__::split($input, $delimiter, $limit = PHP_INT_MAX)
Split a string by string.
__::camelCase($input)
Converts string to camel case.
__::capitalize($input)
Converts the first character of string to upper case and the remaining to lower case.
__::kebabCase($input)
Converts string to kebab case.
__::lowerFirst($input)
Converts the first character of string to lower case, like lcfirst.
__::snakeCase($input)
Converts string to snake case.
__::startCase($input)
Converts string to start case.
__::toLower($input)
Converts string, as a whole, to lower case just like strtolower.
__::toUpper($input)
Converts string, as a whole, to lower case just like strtoupper.
__::upperCase($input)
Converts string, as space separated words, to upper case.
__::upperFirst($input)
Converts the first character of string to upper case, like ucfirst.
__::words($input, $pattern = null)
Splits string into an array of its words.
__::lowerCase($input)
Converts string, as space separated words, to lower case.
Functions
__::slug($string, [array $options])
__::truncate($string, [$limit=40])
Truncate string based on count of words
__::urlify($string)
Find the urls inside a string a put them inside anchor tags
Objects
__::isArray($array)
Check if give value is array or not.
__::isFunction($string)
Check if give value is function or not.
__::isNull($null)
Check if give value is null or not.
__::isNumber($int|$float)
Check if give value is number or not.
__::isObject($object)
Check if give value is object or not.
__::isString($string)
Check if give value is string or not.
Utilities
__::isEmail($string)
Check if the value is valid email.
__::now()
Wrapper of the time()
function that returns the current offset in seconds since the Unix Epoch.
__::stringContains($needle, $haystack, [$offset])
Wrapper of the time()
function that returns the current offset in seconds since the Unix Epoch.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please feel free to contribute to this project! Pull requests and feature requests welcome! :v:
Please see CODE_OF_CONDUCT for details.
Contributors
A huge thanks to all of our contributors:
Mohamed Meabed 💻 ⚠️ 📢 |
Zeeshan Ahmad 💻 🐛 ⚠️ 📖 |
---|
License
The MIT License (MIT). Please see License File for more information.