Download the PHP package tfhinc/ci-ray without Composer
On this page you can find all versions of the php package tfhinc/ci-ray. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tfhinc/ci-ray
More information about tfhinc/ci-ray
Files in tfhinc/ci-ray
Package ci-ray
Short Description Ray is an expressive PHP array class for the Codeigniter framework.
License MIT
Homepage https://github.com/TFHInc/ci-ray
Informations about the package ci-ray
Ray
Ray is an expressive PHP array library for the Codeigniter framework.
Requirements
- PHP >= 7.1.0
- CodeIgnitor 3.x
Installation
Run the post install command to publish the helper and class files to the appropriate CI directories:
Loading the Library
There are a few available options for loading the Warehouse library:
Using the ray()
helper function
The Ray helper function will resolve the Ray
class via the CI instance. It will either load the class or return the existing class instance:
Using the Ray Class
The Ray class can be instantiated when you require it:
Using the Ray CI Library
The Ray class can be loaded like any other CI library:
Usage
Ray
can be used in a variety of ways to manipulate and transfrom arrays.
Method Usage
Ray
enables you to interact with arrays using simple methods that return a single value or a transformed array:
Method Chaining
The power of Ray
is displayed when chaining methods together to manipulate an array:
Method Return Types
Ray
methods will return different data types depedent on the desired outcome of the method. Each documented method definition indicates the data type returned.
-
The
toArray()
method should be called at the end of the method chaining sequence to return the final transformedarray
: - Methods that return a
string
or aninteger
do not require thetoArray()
method. These methods should be called at the end of the method chaining sequence:
Available Methods
The following methods are currently available:
- sortByKeys
- sortByValues
- has
- contains
- sum
- avg
- count
- values
- first
- last
- except
- only
- unique
- groupBy
- column
- where
- whereIn
- whereNot
- whereNotIn
- filter
- reduce
sortByKeys()
Sort the array by its keys.
sortByValues()
Sort the array by its values.
has(string $key)
Determine if the array contains a given key.
contains(string $value [, string $key])
Determine if the array contains a given value.
Optionally provide a key to limit the contains()
check
sum(string $key)
Get the sum of the values for the provided key.
avg(string $key)
Get the average of the values for the provided key.
count()
Get the count of the values.
values()
Get the values of the array. Can be used to reindex the array with consecutive integers.
first()
Get the first value of the array.
last()
Get the last value of the array.
except(array $keys)
Get all array elements except for the provided keys.
only(array $keys)
Only get the array elements for the provided keys.
unique([string $key])
Limit the array by unique value. Optionally limit by unique values of the provided key. The array keys are preserved. If there are duplicate values, the first key/value pair will be retained.
groupBy(string $key)
Group the array by a given key.
column(string $key, [string $key_by])
Retreive an entire column from the array. Optionally key the new transformed array by the provided key_by argument.
where(string $key, string $value)
Limit the array by a specific key and value.
whereIn(string $key, array $values)
Limit the array by a specific key and an array of values.
whereNot(string $key, string $value)
Limit the array by a given key and value.
whereNotIn(string $key, array $values)
Limit the array by a specific key and an array of values.
filter(callable $callback)
Filter the array by the provided callback.
reduce(callable $callback)
Reduce the array by a callback to a single value.
Contributing
Feel free to create a GitHub issue or send a pull request with any bug fixes. Please see the GutHub issue tracker for isses that require help.
Acknowledgements
- Colin Rafuse
- All Contributors
License
The MIT License (MIT). Please see License File for more information.