ExtendedArray for PHP

Today I released an ExtendedArray for PHP, you can check It out in Github.

An example:

use TA\ExtendedArray\Type\ExtendedArray;

$fruits = new ExtendedArray(
    array(
        'tropical' => 'pineapple',
        'farm'     => 'strawberry'
    )
);

$fruits->has('tropical');

// true

$fruits->hasOne(array('tropical', 'asian'));

// true

$fruits->hasAll(array('tropical', 'asian'));

// false

$fruits->get('canary', 'banana');

// 'banana'

$fruits->get('tropical', 'banana');

// 'pineapple'

$fruits->getSubArray(array('tropical'));

// array('tropical' => 'pineapple');

$fruits->toArray();

// array('tropical' => 'pineapple', 'farm' => 'strawberry');

You can access the keys as an object or as an array.

$fruits->tropical;

// 'pineapple'

$fruits['tropical'];

// 'pineapple'

There is more than one way of accessing the properties, I want to give flexibility, but I know there should be only one (obvious) way to use It, feel free to select your way of access.

It uses ArrayObject underneath and You can install ExtendedArray through composer. :-)

Javier Aguirre

Read more posts by this author.

comments powered by Disqus