2017 © Pedro Peláez
 

library array-functions

Some handy array helpers

image

spatie/array-functions

Some handy array helpers

  • Friday, May 4, 2018
  • by Spatie
  • Repository
  • 9 Watchers
  • 128 Stars
  • 8,835 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 11 Versions
  • 5 % Grown

The README.md

, (*1)

Some handy array functions

Latest Version on Packagist Software License Build Status Quality Score SensioLabsInsight Total Downloads, (*2)

This package provides some handy array functions., (*3)

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*4)

Support us

, (*5)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*6)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*7)

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using., (*8)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*9)

The best postcards will get published on the open source page on our website., (*10)

Install

You can install this package via composer:, (*11)

``` bash composer require spatie/array-functions, (*12)


## Usage The following functions are provided in the `Spatie`-namespace: ### array_rand_value ```php /** * Get a random value from an array. * * @param array $array * @param int $numReq The amount of values to return * @return mixed */ function array_rand_value(array $array, $numReq = 1)

array_rand_weighted

/**
 * Get a random value from an array, with the ability to skew the results.
 * Example: array_rand_weighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar.
 * 
 * @param array $key
 * 
 * @return mixed
 */
function array_rand_weighted(array $array)

values_in_array

/**
 * Determine if all given needles are present in the haystack.
 *
 * @param array|string $needles
 * @param array $haystack
 *
 * @return bool
 */
function values_in_array($needles, array $haystack)

array_keys_exist

/**
 * Determine if all given needles are present in the haystack as array keys.
 * 
 * @param array|string $needles
 * @param array $haystack
 *
 * @return bool
 */
function array_keys_exist($needles, array $haystack)

array_split_filter

/**
 * Returns an array with two elements.
 * 
 * Iterates over each value in the array passing them to the callback function.
 * If the callback function returns true, the current value from array is returned in the first
 * element of result array. If not, it is return in the second element of result array.
 *
 * Array keys are preserved.
 *
 * @param array $array
 * @param callable $callback
 * @return array
 *
 */
function array_split_filter(array $array, callable $callback)

array_split

/**
 * Split an array in the given amount of pieces.
 *
 * @param array $array
 * @param int $numberOfPieces
 * @param bool $preserveKeys
 * @throws \InvalidArgumentException
 * @return array
 */
function array_split(array $array, $numberOfPieces = 2, $preserveKeys = false)

array_merge_values

/**
 * Returns an array with the unique values from all the given arrays
 *
 * @param \array[] $arrays
 * @return array
 */
function array_merge_values(array ... $arrays)

array_flatten

/**
 * Flatten an array of arrays. The `$levels` parameter specifies how deep you want to
 * recurse in the array. If `$levels` is -1, the function will recurse infinitely.
 *
 * @param array $array
 * @param int $levels
 *
 * @return array
 */
function array_flatten(array $array, $levels = -1)

Change log

Please see CHANGELOG for more information what has changed recently., (*13)

Testing

You can run the tests with:, (*14)

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details., (*15)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*16)

Credits

About Spatie

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*17)

License

The MIT License (MIT). Please see License File for more information., (*18)

The Versions

04/05 2018

dev-master

9999999-dev https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

08/03 2016

1.8.0

1.8.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

18/11 2015

1.7.0

1.7.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

28/10 2015

1.6.0

1.6.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

21/07 2015

1.5.0

1.5.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

29/06 2015

1.4.0

1.4.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

24/06 2015

1.3.0

1.3.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

22/06 2015

1.2.0

1.2.0.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

22/05 2015

1.1.1

1.1.1.0 https://github.com/spatie/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

21/05 2015

1.1.0

1.1.0.0 https://github.com/freekmurze/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy

20/05 2015

1.0.0

1.0.0.0 https://github.com/freekmurze/array-functions

Some handy array helpers

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

helper array spatie handy