salarmehr/ary 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

salarmehr/ary

最新稳定版本:1.0.0

Composer 安装命令:

composer require salarmehr/ary

包简介

A php array/stdClass alternative to store configs, options and more.

README 文档

README

Ary provides unified interface for ary/object. Really handy to store:

  • arrays/objects those their items/properties varies conditionally.
  • storing registry, system configuration, env variables, etc.
  • when you perform a chain of action on an array/object

It's super cool and after a while you can not code in php without it.

Features

  1. You can access array items using -> or [''] syntax.
  2. You will get null if an index does not exists (instead of a nasty notification!)
  3. You can specify a default value for missing indexes.
  4. You can set/get a value within a deeply nested array using "dot" notation.
  5. A bunch of really handy methods: merge, only, search, toObject, ...
  6. Now, Ary extends Illuminate\Support\Collection class so all of its methods are available (https://laravel.com/docs/master/eloquent-collections)

Examples

// Instantiation
$ary = new Ary();
// or simply
$ary = ary();

//Initialization
$ary = ary(2, 4, 6, 8); // or
$ary = ary([2, 4, 6, 8]); 
$ary = ary(['x' => 'foo', 'y' => 'bar']);

//Assignment
$ary->newItem=20; //or
$ary['newItem']=20;

//Retrieval
$foo = $ary->x; //or
$foo = $ary['x'];
$missed = $ary->get('missed', 'Default value');
$ary->all(); // returns the simple php array;

// works as regular arrays
count($ary); //returns 3
unset($ary[0]); 
json_encode($ary);

// deep assignment/retrieval
$ary = ary(['products' => ['desk' => ['price' => 100]]]);
$value = $ary['products.desk.price']; //100
$ary['production.table.weight']=200; 

Installation

Simply include '__DIR__.'/src/helper.php';

or use Composer:

composer require salarmehr/ary
  • The Ary() requires PHP 5.4 or above.
  • The ary() helper function requires PHP 5.6 or above.

Licence

MIT

统计信息

  • 总下载量: 5.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-01