emeraldinspirations/lib-helper-array

1.1.0 2017-09-05 05:59 UTC

This package is not auto-updated.

Last update: 2024-04-24 01:13:59 UTC


README

Logo of the project

lib-helper-array

A helper in emeraldinspiration's library.

The goal of this project is to hold commonly used functions that assist in manipulating base PHP datatypes.

Installing / Getting started

This project has no dependencies, so can simply be required with composer

composer require emeraldinspirations/lib-helper-array

Features

  • mapElementFunction - Do an array_map using a function inside the array elements
  • xor - Return an array containing elements only in one of the supplied arrays

Example - mapElementFunction

<?php

use emeraldinspirations\library\helper\phpArray\PhpArray;

class DummyObject
{
    public function test(...$Append)
    {
        return $Char . implode('', $Append);
    }
    public function __construct($Char)
    {
        $this->Char = $Char;
    }
}

$Array = [
    new DummyObject('A'),
    new DummyObject('B'),
    new DummyObject('C'),
];

return PhpArray::mapElementFunction('Test', $Array, 1, 2, 3);

// Returns: ['A123', 'B123', 'C123']

Example - xor

<?php

use emeraldinspirations\library\helper\phpArray\PhpArray;

$Array1         = ['Foo', 'FooBar',        'Bar'       ];
$Array2         = [                 'foo', 'Bar', 'bar'];

return PhpArray::xor($Array1, $Array2),

// Returns:       ['Foo', 'FooBar', 'foo',        'bar'];

Contributing

I hope to expand this class to include other functions. If you'd like to contribute, please fork the repository and use a feature branch. I am new to gitHub and am eager to receive a Pull request to learn how it is done.

I am also open to feedback about how well I am being compliant with standards and "best practices." I have written software solo for years, and am trying to learn how to work better with others.

Licensing

The code in this project is licensed under MIT license.