2017 © Pedro Peláez
 

library common

PHP Helpers.

image

northern/common

PHP Helpers.

  • Wednesday, May 30, 2018
  • by northern
  • Repository
  • 2 Watchers
  • 12 Stars
  • 449 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

PHP Common

Build Status, (*1)

PHP Common is a PHP library containing a set of common functionality., (*2)

To run tests use:, (*3)

composer install -v

vendor/bin/phpunit

Find PHP Common on Packagist:, (*4)

ArrayUtil

To use ArrayUtil you need to import it., (*5)

use Northern\Common\Util\ArrayUtil as Arr;

get

To get a value from an array use get:, (*6)

$a = array(
   'foo' => 'bar'
);

$value = Arr::get( $a, 'foo' );

// $value == 'bar'

You can specify a default value in case the key you're trying to retrieve doesn't exists:, (*7)

$value = Arr::get( $a, 'baz', NULL );

// $value == NULL

To get a nested value from an array you can specify a path:, (*8)

$a = array(
   'foo' => array(
      'bar' => array(
         'baz' => 123
      )
   )
);

$value = Arr::get( $a, 'foo.bar.baz' );

// $value == 123

If required, you can use an alternate delimiter:, (*9)

$value = Arr::getPath( $a, 'foo/bar/baz', NULL, '/' );

// $value == 123

set

To set a value or nested value use the set method:, (*10)

$a = array();

Arr::set( $a, 'foo.bar.baz', 123 );

// $a = array( 'foo' => array( 'bar' => array( 'baz' => 123 ) ) );

If the key or path not already exist, it will be created., (*11)

insert

With insert you can create a new value at a path or key, however, the path will only be created if it does not yet exists., (*12)

$a = array();

Arr::set( $a, 'foo.bar.baz', 123 );

Arr::insert( $a, 'foo.bar.baz', 123 );

// The insert statement does nothing.

delete

It's also possible to delete a key or path:, (*13)

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

Or to delete multiple paths or keys at once:, (*14)

Arr::delete( $a, array('fum', 'foo.bar.baz', 'foo.bar.bob') );

Or with an alternate delimiter:, (*15)

Arr::delete( $a, array('fum', 'foo/bar/baz', 'foo/bar/bob'), '/' );

exists

To test if a key or path exists use:, (*16)

$value = Arr::exists( $a, 'foo.bar.baz' );

// $value == TRUE

prefix

If you need to prefix all the values in an array, use the prefix method:, (*17)

$a = array('1', '2', '3');

$values = Arr::prefix( $a, '$' );

// $values = array('$1', '$2', '$3');

postfix

If you need to postfix all the values in an array, use the postfix method:, (*18)

$a = array('1', '2', '3');

$values = Arr::postfix( $a, '$' );

// $values = array('1$', '2$', '3$');

flatten

Sometimes you need to "flatten" an array, i.e. glueing the keys and values together with a symbol or character:, (*19)

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::flatten( $a );

// $values = array('param1=123', 'param2=xyz');

Or use a different 'glue' character from the default '=':, (*20)

$values = Arr::flatten( $a, '|' );

// $values = array( 'param1|123', 'param2|xyz' );

keys

Returns the keys of an array in the same way the array_keys function works, however, keys allows you to specifiy a prefix:, (*21)

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::keys( $a, '&' );

// $values = array( '&param1', '&param2' )

values

Returns the values of an array in the same way the array_values function works, however, values allows you to specify a prefix:, (*22)

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::values( $a, '&' );

// $values = array( '&123', '&xyz' )

contains

Tests if the values of one array exist in another. E.g:, (*23)

$b = Arr::contains( array('A', 'B'), array('A', 'B', 'C') );

// $b = TRUE

The above tests if the values of the first array (needle) exist in the second array (haystack), which in the above example is true., (*24)

extract

Returns a value from an array and deletes the key in the array., (*25)

$a = array(
   'foo' => 'bar'
);

$value = Arr::extract( $a, 'foo' );

// $value == 'bar'
// $a = array()

The above example returns the value for foo from the array and deletes the foo key from the array., (*26)

The Versions

30/05 2018

dev-master

9999999-dev

PHP Helpers.

  Sources   Download

GPL GPL-2.0-only

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

30/05 2018

2.0.8

2.0.8.0

PHP Helpers.

  Sources   Download

GPL-2.0-only

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

30/05 2018

dev-dev-master

dev-dev-master

PHP Helpers.

  Sources   Download

GPL GPL-2.0-only

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

01/02 2018

2.0.7

2.0.7.0

PHP Helpers.

  Sources   Download

GPL-2.0-only

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

28/09 2017

2.0.6

2.0.6.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

11/05 2017

2.0.5

2.0.5.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

06/02 2017

2.0.4

2.0.4.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

18/11 2016

2.0.3

2.0.3.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

25/07 2016

2.0.2

2.0.2.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

04/02 2016

2.0.1

2.0.1.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

04/02 2016

2.0.0

2.0.0.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

12/02 2015

1.2.6

1.2.6.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

10/02 2015

1.2.5

1.2.5.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

30/01 2015

1.2.4

1.2.4.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

27/01 2015

1.2.3

1.2.3.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

30/12 2014

1.2.2

1.2.2.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

30/08 2014

1.2.1

1.2.1.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

24/08 2014

1.2.0

1.2.0.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

07/06 2014

dev-feature-filter-helper

dev-feature-filter-helper

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

11/05 2014

1.1.0

1.1.0.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern

10/04 2014

1.0.0

1.0.0.0

PHP Helpers.

  Sources   Download

GPL

The Requires

  • php >=5.3.3

 

The Development Requires

helpers common northern