roquie / collection
此包已被放弃,不再维护。未建议替代包。
基于Laravel 5 Collection的简单PHP集合
0.1.11
2015-12-11 08:53 UTC
Requires
- php: >=5.5.0
README
已弃用。请使用原始的Laravel集合。此包不再维护。
基于Laravel 5 Collection的简单PHP集合。
安装
composer require roquie/collection
用法(进行中...)
五分钟示例
$array = [ 'foo' => [ 'one', 'two', 'three', 'bar' => [ 1, 2, 3 ], 'clean' => '', 'test1' => 'val2qq', 'test2' => 'val2ww' ] ]; $collection = Collection::make($array); //1 foreach($collection as $collect) { echo $collect['undefined_index']; // null } //2 $result = $collection->each(function($collect) { echo $collect['undefined_index']; // null }); //3 $result = $collection->filter(function($collect) { return $collect->has('key'); }); //4. get items using "dot" notation $collection->get('foo.0', <default>); $collection->getArray('foo.0'); // return [] if empty $collection->getInteger('foo.0'); // return 0 if empty $collection->getBoolean('foo.0'); // return false if empty $collection->getString('foo.0'); // return '' if empty //5. remove item using "dot" notation $collection->rm('foo.bar'); // delete an item //6. has item using "dot" notation $collection->rm('foo.bar'); // true (if not delete :) ) $collection->forgot('foo.bar'); //alias //7. clean array $collection->clean(); // key foo.clean deleted. $collection->clean('val'); // keys foo.test1 and 2 will be removed //8. set an item using "dot" notation $collection->set('baz', ['key' => 'is awesome']); $collection->put($key, $value); //alias
许可
MIT