3aa13cff4b3e611e0acbb7050c2e8bcb3128530f
Ary
Are you tired from casting objects and arrays to each other? Don't do that anymore! Ary is a light class/function that makes accessing array items more convenient.
- You can access array items using
->or['']syntax. - You will get
nullif an index does not exists (instead of a nasty notification!) - You can specify a default value for missing indexes.
- It extends PHP ArrayObject class. So you can use its methods.
- The class (
Ary()) requires PHP 5.4 or newer. - The helper function (
ary()) requires PHP 5.6 or newer.
// instantiation
$ary = new Ary();
// or simply
$ary = ary();
//setting and getting array items.
$ary = ary(2, 4, 6, 8); //or
$ary = ary([2, 4, 6, 8]);
$ary = ary(['x' => 'foo', 'y' => 'bar']);
$foo = $ary->x; //or
$foo = $ary['x'];
$missed = $ary->get('missed', 'Default value');
$ary->newItem=20; //or
$ary['newItem']=20;
count($ary); //returns 3
$ary->all(); // returns simple php array;
Installation
composer require salarmehr/ary
Description
Ary makes PHP's array syntax more flexible and provides some really necessary utility methods.
Languages
PHP
100%