madesimple/php-arrays 问题修复 & 功能扩展

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

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

madesimple/php-arrays

最新稳定版本:v3.0.0

Composer 安装命令:

composer require madesimple/php-arrays

包简介

Helper functions for manipulating arrays

README 文档

README

PHPUnit

Helper functions for manipulating arrays.

Arr & ArrDots

Arr and ArrDots contains a set of static helper methods for arrays. These methods can be used on both array and \ArrayAccess objects. See the PHPDocs inside the classes for more information.

Dots

Dots is an implementation of \ArrayAccess that uses the functions from \MadeSimple\ArrDots. Instances of Dots can be passed into ArrDots as if it were an array.

There are three ways to create a Dots:

// Create an empty dot array
$dots = new \MadeSimple\Dots();

// Create a dot array with a pre-existing array
$dots = new \MadeSimple\Dots($array);

// Create a dot array with 
$dots = new \MadeSimple\Dots([
    'address' => [
        'houseNo'  => '123',
        'street'   => 'Fake St',
        'postCode' => 'AB12 3CD',
    ],
    'comments' => [
        'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
        'Donec nec pellentesque est.',
        'Quisque volutpat quam et est laoreet, vitae consectetur erat molestie.',
    ]
]);

Once a Dots is created you can replace the underlining array in the following ways:

// Set an array after dot array
// Changes will _not_ be reflected in the original array
$dots->setArray($array);

// Set an array as a reference
// Changes will be reflected in the original array
$dots->setReference($array);

Basic usage of Dots:

// Get a value using dot notation:
echo "Post Code: ", $dots['address.postCode'], PHP_EOL;

// Set a value using dot notation:
$dots['address.postCode'] = 'EF45 6GH';
echo "Post Code: ", $dots['address.postCode'], PHP_EOL;

// Remove a value using dot notation:
unset($dots['address.postCode']);
echo "Exists: ", (isset($dots['address.postCode']) ? 'yes' : 'no'), PHP_EOL;

// Add a value using dot notation:
$dots['address.postCode'] = 'IJ78 9KL';
echo "Post Code: ", $dots['address.postCode'], PHP_EOL;

// Access nth element in an sub array
echo "Comment: ", $dots['comments.1'], PHP_EOL;

统计信息

  • 总下载量: 16.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-29