2017 © Pedro Peláez
 

library arr

The Array Component contains methods that can be useful when working with arrays.

image

flextype-components/arr

The Array Component contains methods that can be useful when working with arrays.

  • Monday, April 30, 2018
  • by Awilum
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Arr Component

versionMIT License, (*1)

The Array Component contains methods that can be useful when working with arrays., (*2)

Installation

composer require flextype-components/arr

Usage

use Flextype\Component\Arr\Arr;

Sorts a multi-dimensional array by a certain column, (*3)

$new_array = Arr::sort($old_array, 'title');

Sets an array value using "dot notation"., (*4)

Arr::set($array, 'foo.bar', 'value');

Return value from array using "dot notation".
If the key does not exist in the array, the default value will be returned instead., (*5)

$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');

Delete an array value using "dot notation"., (*6)

Arr::delete($array, 'foo.bar');

Checks if the given dot-notated key exists in the array., (*7)

if (Arr::keyExists($array, 'foo.bar')) {
    // Do something...
}

Returns a random value from an array., (*8)

$random = Arr::random(array('php', 'js', 'css', 'html'));

Returns TRUE if the array is associative and FALSE if not., (*9)

if (Arr::isAssoc($array)) {
    // Do something...
}

Returns TRUE if the array is associative and FALSE if not., (*10)

$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')

Converts an array to a JSON string, (*11)

$array = [
  'cat'  => 'miao',
  'dog'  => 'wuff',
  'bird' => 'tweet'
];

echo Arr::json($array);
// output: {"cat":"miao","dog":"wuff","bird":"tweet"}

Returns the first element of an array, (*12)

$array = [
  'cat',
  'dog',
  'bird',
];

$first = Arr::first($array);
// first: 'cat'

Returns the last element of an array, (*13)

$array = [
  'cat',
  'dog',
  'bird',
];

$last = Arr::last($array);
// first: 'bird'

Converts an array to a JSON string, (*14)

$array = [
   'cat'  => 'miao',
   'dog'  => 'wuff',
   'bird' => 'tweet'
];

// output: {"cat":"miao","dog":"wuff","bird":"tweet"}
echo Arr::toJson($array);

Create an new Array from JSON string., (*15)

$str = '{"firstName":"John", "lastName":"Doe"}';

// Array['firstName' => 'John', 'lastName' => 'Doe']
$array = Arr::createFromJson($str);

Create an new Array object via string., (*16)

$array = Arr::createFromString('cat, dog, bird', ',');

Counts all elements in an array., (*17)

$size = Arr::size($array);

Return an array with elements in reverse order., (*18)

$array = Arr::reverse($array);

License

See LICENSE, (*19)

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/flextype-components/arr

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

30/04 2018

v1.2.2

1.2.2.0 https://github.com/flextype-components/arr

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

26/04 2018

v1.2.1

1.2.1.0 https://github.com/flextype-components/arr

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

26/04 2018

v1.2.0

1.2.0.0 https://github.com/flextype-components/arr

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

11/04 2018

v1.1.1

1.1.1.0 https://github.com/flextype-components/array

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

05/04 2018

v1.1.0

1.1.0.0 https://github.com/flextype-components/array

The Array Component contains methods that can be useful when working with arrays.

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

array

27/10 2015

v1.0.2

1.0.2.0 https://github.com/force-components/Arr/issues

Simple Array Class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

array