Arr


Class: \Flextype\Component\Arr\Arr

Visibility Function
public static average(array $array, int/\integer $decimals) : int/\Flextype\Component\Arr\double
Returns the average value of the current array. echo Arr::average([2, 5, 1, 9], 2);
public static createFromJson(\string $json, \boolean $assoc=true, \integer $depth=512, \integer $options) : array
Create an new Array from JSON string. $str = '{"firstName":"John", "lastName":"Doe"}'; // Array['firstName' => 'John', 'lastName' => 'Doe'] $array = Arr::createFromJson($str);
public static createFromString(\string $str, \string $delimiter=null, \string $regEx=null) : array
Create an new Array object via string. $array = Arr::createFromString('cat, dog, bird', ',');
public static delete(array $array, \string $path) : bool
Deletes an array value using "dot notation". Arr::delete($array, 'foo.bar');
public static first(array $array) : mixed The first element
Returns the first element of an array $array = [ 'cat', 'dog', 'bird', ]; $first = Arr::first($array); // first: 'cat'
public static get(array $array, \string $path, mixed $default=null) : mixed
Returns value from array using "dot notation". If the key does not exist in the array, the default value will be returned instead. $login = Arr::get($_POST, 'login'); $array = array('foo' => 'bar'); $foo = Arr::get($array, 'foo'); $array = array('test' => array('foo' => 'bar')); $foo = Arr::get($array, 'test.foo');
public static isAssoc(array $array) : bool
Returns TRUE if the array is associative and FALSE if not. if (Arr::isAssoc($array)) { // Do something... }
public static keyExists(array $array, mixed $path) : bool
Checks if the given dot-notated key exists in the array. if (Arr::keyExists($array, 'foo.bar')) { // Do something... }
public static last(array $array) : mixed The last element
Returns the last element of an array $array = [ 'cat', 'dog', 'bird', ]; $last = Arr::last($array); // first: 'bird'
public static overwrite(array $array1, array $array2) : array
Overwrites an array with values from input arrays. Keys that do not exist in the first array will not be added! $array1 = array('name' => 'john', 'mood' => 'happy', 'food' => 'bacon'); $array2 = array('name' => 'jack', 'food' => 'tacos', 'drink' => 'beer'); // Overwrite the values of $array1 with $array2 $array = Arr::overwrite($array1, $array2); // The output of $array will now be: array('name' => 'jack', 'mood' => 'happy', 'food' => 'tacos')
public static random(array $array) : mixed
Returns a random value from an array. Arr::random(array('php', 'js', 'css', 'html'));
public reverse(array $array, \boolean $preserve_keys=false) : array
Return an array with elements in reverse order. $array = Arr::reverse($array); Non-numeric keys are not affected by this setting and will always be preserved.
public static set(array $array, \string $path, mixed $value) : void
Sets an array value using "dot notation". Arr::set($array, 'foo.bar', 'value');
public static size(array $array, int/\integer $mode) : int
Counts all elements in an array. $size = Arr::size($array); COUNT_RECURSIVE (or 1), count will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. count does not detect infinite recursion.
public static sort(array $array, \string $field, \string $direction='ASC', \Flextype\Component\Arr\const $method) : array
Sorts a multi-dimensional array by a certain column $new_array = Arr::sort($old_array, 'title');
public static toJson(array $array, \integer $options, \integer $depth=512) : string The JSON string
Converts an array to a JSON string $array = [ 'cat' => 'miao', 'dog' => 'wuff', 'bird' => 'tweet' ]; // output: {"cat":"miao","dog":"wuff","bird":"tweet"} echo Arr::toJson($array);
Language: en, ru