定制 vk-php-utils/ds 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vk-php-utils/ds

最新稳定版本:0.0.0

Composer 安装命令:

composer require vk-php-utils/ds

包简介

PHP Java-Like Collections (List, Set, Map)

README 文档

README

Overview

php-utils-ds is a PHP library that provides Java-like implementations for List, Set, and Map. It offers data structures such as ArrayList, Set, and Map, which closely resemble their Java counterparts, making it easier for Java developers to work with PHP.

This library is compatible with PHP 8.2 and above.

Features

  • ArrayList: A dynamic array that provides methods to manipulate and access its elements.
  • Set: A collection that contains no duplicate elements. It is similar to a mathematical set.
  • Map: An object that maps keys to values. It cannot contain duplicate keys; each key can map to at most one value.

Installation

You can install the php-utils-ds library via Composer. Run the following command:

composer require vk-php-utils/ds

Usage

Here are some examples of how to use the php-utils-ds library:

ArrayList

use VKPHPUtils\DS\ArrayList;

$list = new ArrayList(1, 2, 3);
$list->add(4);
$list->remove(2);

foreach ($list as $element) {
    echo $element . PHP_EOL;
}

Set

use VKPHPUtils\DS\Set;

$set = new Set(1, 2, 3, 3, 4);
$set->add(5);
$set->remove(2);

foreach ($set as $element) {
    echo $element . PHP_EOL;
}

Map

use VKPHPUtils\DS\Map;

/** @var User $user1 **/
$user1 = ...;
/** @var User $user2 **/
$user2 = ...;

/** @var Map<User, Address> $addressMap **/
$addressMap = new Map();
$addressMap->put($user1, new Address('Apple str 18'));
$addressMap[$user2] = new Address('Banana str 19'); // php way

echo $map->get($user1)->street; // Output: Apple str 18

// php way
echo $map[$user1]->street; // Output: Apple str 18

Contributing

Contributions to the php-utils-ds library are welcome. If you find a bug or want to add a new feature, feel free to open an issue or submit a pull request.

License

php-utils-ds is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-03