cygnite/array-manipulator 问题修复 & 功能扩展

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

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

cygnite/array-manipulator

最新稳定版本:v1.3

Composer 安装命令:

composer require cygnite/array-manipulator

包简介

Array Element Reader As String Path

README 文档

README

Cygnite Array Manipulator component used for simple array manipulation and reading array value using simple string path.

#Installation

Array Manipulator uses Composer for installation. For installing composer documentation, please refer to getcomposer.org. Add following into your composer.json.

"cygnite/array-manipulator" : "1.*"

#Usage

Cygnite array accessor used to read values from multi multidimensional array. It helps when you want to beautify your syntax and easy to access values. You can read values as below.

#Example

$array = [
         'profile' => [
             "experience"  => [
                 "field" => "Web Development",
                 "technology"    => "PHP"
             ]
         ]
     ];
$arrayAccessor = (new ArrayAccessor())->set($array);
echo $arrayAccessor->toString('profile.experience.field'); // output: Web Development

In some cases your array key may contains dot(.) which will make system confused whether it should look for next key or same. In such cases while getting value you need to provide key as underscore or dash prefix as below.

$array2 = [
         'profile' => [
             "experience"  => [
                 "technology.version"  => "Welcome to PHP v5.4"
             ]
         ]
     ];
$arrayAccessor = (new ArrayAccessor())->set($array1);
echo $arrayAccessor->toString('profile.experience.technology_version'); // output: Welcome to PHP v5.4

#Getting default value if array element not exists

$array3 = [
         'profile' => [
             "experience"  => '4 Years'
         ]
     ];
$arrayAccessor = (new ArrayAccessor())->set($array3);
echo $arrayAccessor->toString('profile.experience.area', 'Application Development'); // output 5 years

Using Closure Syntax

$array4 = [
         'profile' => [
             "author"  => 'Sanjoy Dey'
         ]
     ];
$arrayAccessor = ArrayAccessor::make(function($a) use ($array4)
{
    return $a->set($array4);
});
echo $arrayAccessor->toString('profile.author');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-07