A collection of utility methods for Strings, Arrays and Numbers. A must-have in most projects.
composer require creativestyle/utilities
Assuming that you've got an array of associate arrays ($table
) this method
will return a single-dimensional array with values of the selected key ($column
).
Picks selected $keys
from the $subject
associative array.
Maps the array allowing you to change the keys.
Callback is called with ($key
, $value
) parameters and shall return a [$newkey => $newvalue]
array.
It's possible to map a single entry to multiple by returning more than one item from the $callback
.
Averages array values. If key is set then the column indicated by key is averaged.
Returns long string of digits.
Returns random bool with $trueChance
[0, 1] of returning true
.
Returns random array element.
Returns $count
unique random elements from the $array
.
If the desired number of results is equal or greater to the array size then the array is shuffled. If it's less or equal to 0, then empty array is returned.
Returns a random number from gaussian distribution with desired params.
Returns a random number from normal distribution with desired params.
Transliterates the text keeping only alphanumeric characters and -
.
Whitespace is collapsed and transformed to -
.
Alias to urlize()
.
Behaves the same way as implode
but skips empty array elements.
Checks if $haystack
ends with $needle
.
Checks if $haystack
starts with $needle
.
Converts the string To The Title Case.
Capitalizes the string (same as ucfirst
) in a multibyte-safe manner.
Humanizes a camelCase variable name. For example virtualRealityInterposer
will become Virtual reality interposer
.
Works similar to humanize
but converts const names like VIRTUAL_REALITY_INTERPOSER
.
Returns true if the value can be converted to string (is a scalar or has __toString
method).