wake/php-array-kit 问题修复 & 功能扩展

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

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

wake/php-array-kit

最新稳定版本:v0.4.2

Composer 安装命令:

composer require wake/php-array-kit

包简介

Simple functions help using array in php

README 文档

README

Simple functions help using array in php.

Usage

keyi ($array, $key, $gather = false)

Split array base on key

  $input = [
    ['id' => 'A', 'title' => 'A apple', 'value' => 10],
    ['id' => 'B', 'title' => 'B bear',  'value' => 27],
    ['id' => 'C', 'title' => 'C Cat',   'value' => 10],
  ];

  // Split array base on key

  $output = keyi ($input, 'id');

  /*
  [
    'A' => ['id' => 'A', 'title' => 'A apple', 'value' => 10],
    'B' => ['id' => 'B', 'title' => 'B bear',  'value' => 27],
    'C' => ['id' => 'C', 'title' => 'C Cat',   'value' => 10],
  ];
  */

  // Base on multiple keys

  $output = keyi ($input, ['id', 'title']);

  /*
  [
    'A' => [
      'A apple' => ['id' => 'A', 'title' => 'A apple', 'value' => 10]
    ],
    'B' => [
      'B bear'  => ['id' => 'B', 'title' => 'B bear',  'value' => 27]
    ],
    'C' => [
      'C Cat'   => ['id' => 'C', 'title' => 'C Cat',   'value' => 10]
    ],
  ];
  */

  // Gather elements

  $output = keyi ($input, 'value', true);

  /*
  [
    '10' => [
      ['id' => 'A', 'title' => 'A apple', 'value' => 10],
      ['id' => 'B', 'title' => 'B bear',  'value' => 27],
    ],
    '27' => [
      ['id' => 'C', 'title' => 'C Cat',   'value' => 10],
    ]
  ];
  */

dig ($array, $key = false, $deep = 1)

Dig value from array

  $input = [
    'A' => [
      'id' => 'A',
      'A apple' => [
        'value' => 10
      ]
    ],
    'B' => [
      'id' => 'B',
      'B bear' => [
        'value' => 27
      ]
    ],
    'C' => [
      'id' => 'C',
      'C Cat' => [
        'value' => 10
      ]
    ],
  ];

  // Dig value from array

  $output = dig ($input, 'id');

  /*
  [
    0 => 'A',
    1 => 'B',
    2 => 'C',
  ];
  */

  // Dig deeply

  $output = dig ($input, 'value', 2);

  /*
  [
    0 => 10,
    1 => 27,
    2 => 10,
  ];
  */

otoa ($object)

Object to array, get array from object values.

Installation

Add in your composer.json with following require entry:

{
  "require": {
    "wake/php-array-kit": "*"
  }
}

or using composer:

$ composer require wake/php-array-kit:*

then run composer install or composer update.

Feedback

Please feel free to open an issue and let me know if there is any thoughts or questions 😃

License

Released under the MIT license

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固