Download the PHP package awssat/array-helper without Composer
On this page you can find all versions of the php package awssat/array-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download awssat/array-helper
More information about awssat/array-helper
Files in awssat/array-helper
Package array-helper
Short Description A flexible & powerful array manipulation helper for PHP
License MIT
Homepage https://github.com/awssat/array-helper
Informations about the package array-helper
array-helper
⚡️ A flexible, simple & yet powerful array manipulation helper for PHP. It gives you the magic of method chaining and it's easier and shorter to be included in views. It Supports most of PHP built-in array functions
Features
- Support All PHP array functions.
- Short methods names, no need to write "array_" like array_map can be only map(..)
- Array items can be retrireve or updated as properties or keys [->key or [key] ]
- Support powefull conditional methods. if, else, if{AnyMethod}, endif.
- Support camelCase and snake-case methods name.
- Useful new methods like equal, exists .. etc
Install/Use
You can install the package via composer locally in your project folder:
After installing it, just start using the helper arr([...])
or ArrayHelper::make([...])
Examples
Use any array function, no need for "array_", if you like it you can use it as in array_filter or arrayFilter .. all will work.
You can use conditions, if(function() {...}), if{AnyMethod}, else(), endif()
you may also use useful method with if
like ifEmpty
, ifKeyExists
or ifEqual
etc.
get() will return all items, while get(index) return a item in the array. all() is alias for get(all, true) which will ignore conditions and force return of items anyway.
The example above can be shortened using all() like this:
You can use do(callback) to run a callback on the array.
PHP built-in array_map, array_walk, array_filter, and array_reduce are the best!
array_map to loop through all items and change them.
or for simple functions use, $array->map('trim')
array_walk can be used for looping without changing items
or if you want to change the values
array_filter is great for filtering an array
or just $array->filter()
to remove any value equal to FALSE.
Tests
Simply use:
Credits
- Abdulrahman M.
- All Contributors
License
The MIT License (MIT). Please see License File for more information.