weew/helpers-array

Useful collection of php array helpers.

v1.3.1 2016-07-21 11:18 UTC

This package is not auto-updated.

Last update: 2024-12-17 22:37:45 UTC


README

Build Status Test Coverage Version Licence

Table of contents

Installation

composer require weew/helpers-array

Introduction

This tiny library provides various helper functions to deal with arrays.

Functions

array_get

Get an item from an array using "dot" notation.

mixed array_get(array $array, mixed $key [, mixed $default = null])

array_has

Check if an item exists in an array using "dot" notation.

bool array_has(array $array, mixed $key)

array_set

Set an array item to a given value using "dot" notation.

array array_set(array &$array, mixed $key, mixed $value)

array_remove

Remove one or many array items from a given array using "dot" notation.

void array_remove(array &$array, mixed $keys)

array_add

Add an element to the array at a specific location using the "dot" notation.

array array_add(array &$array, mixed $key, mixed $value)

array_take

Get an element and remove it from the array using the "dot" notation.

array array_take(array &$array, mixed $key, [, mixed $default = null])

array_first

Get the first element from an array.

array array_first(array &$array, [, mixed $default = null])

array_last

Get the last element from an array.

array array_last(array &$array, [, mixed $default = null])

array_reset

Reset all numerical indexes of an array (start from zero). Non-numerical indexes will stay untouched.

array array_reset(array $array [, bool $deep = false])

array_dot

Flatten a multi-dimensional associative array with dots.

array array_dot(array $array [, string $prepend = ''])

array_extend

Extend one array with another.

array array_extend(array $arrays [, array $...])

array_extend_distinct

Extend one array with another. Non associative arrays will not be merged but rather replaced.

array array_extend_distinct(array $arrays [, array $...])

array_is_associative

Check if the given array is associative.

bool array_is_associative(array $array)

array_is_indexed

Check if an array has a numeric index.

bool array_is_indexed(array $array)

array_contains

Check if array contains a specific element.

array array_contains(array $array, mixed $search [, bool $strict = true])