Download the PHP package phannaly/laravel-helpers without Composer
On this page you can find all versions of the php package phannaly/laravel-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-helpers
The PHP helpers function extract from Laravel
This project is independently you don't need to install anything(composer) unless you want to contribute.
Most of the code extract from Laravel codebase.
Requirements
- PHP 7.0 or higher
Setup
You don't need to install by composer if your project doesn't have it.
Just import it manually in src
folder.
But If you want to install by composer, please follow command below
composer require phannaly/laravel-helpers
This library will load automatically after you install it. Done!, you are good to go.
Available Methods
Arrays & Objects
- array_add
- array_collapse
- array_divide
- array_dot
- array_except
- array_first
- array_flatten
- array_forget
- array_get
- array_has
- array_last
- array_only
- array_pluck
- array_prepend
- array_pull
- array_random
- array_set
- array_sort
- array_sort_recursive
- array_where
- array_wrap
- data_fill
- data_get
- data_set
- head
- last
Strings
- camel_case
- ends_with
- kebab_case
- preg_replace_array
- snake_case
- starts_with
- str_after
- str_before
- str_contains
- str_finish
- str_is
- str_limit
- str_random
- str_replace_array
- str_replace_first
- str_replace_last
- str_slug
- str_start
- studly_case
- title_case
Arrays & Objects
array_add()
The array_add
function adds a given key / value pair to an array if the given key doesn't already exist in the array:
array_collapse()
The array_collapse
function collapses an array of arrays into a single array:
array_divide()
The array_divide
function returns two arrays, one containing the keys, and the other containing the values of the given array:
array_dot()
The array_dot
function flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth:
array_except()
The array_except
function removes the given key / value pairs from an array:
array_first()
The array_first
function returns the first element of an array passing a given truth test:
A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:
array_flatten()
The array_flatten
function flattens a multi-dimensional array into a single level array:
array_forget()
The array_forget
function removes a given key / value pair from a deeply nested array using "dot" notation:
array_get()
The array_get
function retrieves a value from a deeply nested array using "dot" notation:
The array_get
function also accepts a default value, which will be returned if the specific key is not found:
array_has()
The array_has
function checks whether a given item or items exists in an array using "dot" notation:
array_last()
The array_last
function returns the last element of an array passing a given truth test:
A default value may be passed as the third argument to the method. This value will be returned if no value passes the truth test:
array_only()
The array_only
function returns only the specified key / value pairs from the given array:
array_pluck()
The array_pluck
function retrieves all of the values for a given key from an array:
You may also specify how you wish the resulting list to be keyed:
array_prepend()
The array_prepend
function will push an item onto the beginning of an array:
If needed, you may specify the key that should be used for the value:
array_pull()
The array_pull
function returns and removes a key / value pair from an array:
A default value may be passed as the third argument to the method. This value will be returned if the key doesn't exist:
array_random()
The array_random
function returns a random value from an array:
You may also specify the number of items to return as an optional second argument. Note that providing this argument will return an array, even if only one item is desired:
array_set()
The array_set
function sets a value within a deeply nested array using "dot" notation:
array_sort()
The array_sort function sorts an array by its values:
You may also sort the array by the results of the given Closure:
array_sort_recursive()
The array_sort_recursive
function recursively sorts an array using the sort
function for numeric sub=arrays and ksort
for associative sub-arrays:
array_where()
The array_where
function filters an array using the given Closure:
array_wrap()
The array_wrap
function wraps the given value in an array. If the given value is already an array it will not be changed:
If the given value is null, an empty array will be returned:
data_fill()
The data_fill
function sets a missing value within a nested array or object using "dot" notation:
This function also accepts asterisks as wildcards and will fill the target accordingly:
data_get()
The data_get
function retrieves a value from a nested array or object using "dot" notation:
The data_get
function also accepts a default value, which will be returned if the specified key is not found:
data_set()
The data_set
function sets a value within a nested array or object using "dot" notation:
This function also accepts wildcards and will set values on the target accordingly:
By default, any existing values are overwritten. If you wish to only set a value if it doesn't exist, you may pass false
as the third argument:
head()
The head
function returns the first element in the given array:
last()
The last
function returns the last element in the given array:
Strings
camel_case()
The camel_case
function converts the given string to camelCase
:
ends_with()
The ends_with
function determines if the given string ends with the given value:
kebab_case()
The kebab_case
function converts the given string to kebab-case
:
preg_replace_array()
The preg_replace_array
function replaces a given pattern in the string sequentially using an array:
snake_case()
The snake_case
function converts the given string to snake_case
:
starts_with()
The starts_with
function determines if the given string begins with the given value:
str_after()
The str_after
function returns everything after the given value in a string:
str_before()
The str_before
function returns everything before the given value in a string:
str_contains()
The str_contains
function determines if the given string contains the given value (case sensitive):
You may also pass an array of values to determine if the given string contains any of the values:
str_finish()
The str_finish
function adds a single instance of the given value to a string if it does not already end with the value:
str_is()
The str_is
function determines if a given string matches a given pattern. Asterisks may be used to indicate wildcards:
str_limit()
The str_limit
function truncates the given string at the specified length:
You may also pass a third argument to change the string that will be appended to the end:
str_random()
The str_random
function generates a random string of the specified length. This function uses PHP's random_bytes
function:
str_replace_array()
The str_replace_array
function replaces a given value in the string sequentially using an array:
str_replace_first()
The str_replace_first
function replaces the first occurrence of a given value in a string:
str_replace_last()
The str_replace_last
function replaces the last occurrence of a given value in a string:
str_slug()
The str_slug
function generates a URL friendly "slug" from the given string:
str_start()
The str_start
function adds a single instance of the given value to a string if it does not already start with the value:
studly_case()
The studly_case
function converts the given string to StudlyCase
:
title_case()
The title_case
function converts the given string to Title Case
:
Contributing
Feel free to contribute through PR.
See CODE OF CONDUCT for details.
License
This package operates under the MIT License (MIT). See the LICENSE file for details.